GameMaker: Studio

GameMaker: Studio

Ver estatísticas:
Hoonster 9 mar. 2015 às 8:03
Is it possible to rename an object through coding?
I am trying to create a puzzle game similar to Candy Crush . . and I am trying to create an event when two objects are selected in the game.

However, just like Candy Crush, I need different events to occur depending on the relative position of the two selected objects.

I am currently trying to accomplish this through renaming object.

As in I would like rename object that was selected first to Obj_first and rename object that was selected second to Obj_second.

That way I can check the relative location through

if x-Obj_second.x > 20
{
create_instance(Obj_bollocks)
}

or something similar;

Sorry if I am not making sense;
< >
A mostrar 1-3 de 3 comentários
Sera 9 mar. 2015 às 9:21 
You can't rename an object, but you can assign an instance to a variable. So, as an example, on mouse click you could use instance_place() to do something like

First = instance_place(mouse_x, mouse_y, obj_Shiny);

(Note that this assumes al of your color-coded clickable doo-dads are either instances of obj_Shiny or objects that have obj_Shiny as a parent, as otherwise you'll need to check for every different object type ie. obj_Green, obj_Red, etc., which is pretty tedious and not fun.)
Hoonster 9 mar. 2015 às 16:05 
Thank you so much for your reply! I am, however, still bit confused as what instance_place() does.

Is it possible to use First.x and First.y globally after

First = instance_place(mouse_x, mouse_y, obj_shiny);

?
Sera 9 mar. 2015 às 17:22 
instance_place() will find the instance of the given object at the position given and return it (unless there isn't one, which is probably something you'll want to check for, thinking about it.) In this case, it would pass that instance id to First, which then can be used to refer to that instance whenever you want.

So, yes, First.x, First.y, and all that good business will work, provided there is an instance stored to First in the first place. (To that end, you'll want to build some logic around it, ie. if First != 0, before trying to do anything with the variable.) In a match-3 scenario, just make sure to revert First back to 0 when the selecting and moving and such is all complete; if the object in question gets destroyed, looking up First.anything will most likely result in the game crashing, since that object instance (and thus its variables) no longer exist.
< >
A mostrar 1-3 de 3 comentários
Por página: 1530 50

Postado a: 9 mar. 2015 às 8:03
Comentários: 3