• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Seeing syntax examples

J

Joe Banko

Guest
Hi all,

How can I see examples of scripting instead of Drag & Drop examples in the manual? Is there a help switch to show GML versus D&D?

Thanks,

Joe B
 

JeffJ

Member
Also, whenever a function is typed out in the code editor, you can middle click it (with your mouse wheel) and it will directly open the manual entry on that particular function. For just about every (if not every) function, there's at the very least a little example code snippet related to it, that's usually very helpful. Besides working as a great example for how to use the function, it's also another great way to see little syntax examples that are relevant to what your're looking up at that moment.
 
J

Joe Banko

Guest
Thanks all!
Just learning the language so I'm probably asking dumb questions. This is exactly what I'm looking for:
I have an array of strings, sprites_array[x] for a character which has both left and right animations. I have an enum array of "states", i.e. IDLE, WALK, ATTACK that I use to get the correct base name of the sprite and I am trying to get to the mask_index for that spite and I am using the following code:

sprite_index = string(sprites_array[state] + choose(facing, "R", "L"));
mask_index = sprite_index;
I get an error can't convert string to integer. I may be reading the docs wrong but don't you set mask index equal to a string. From the manual:

Example:
mask_index = spr_Round;

The above code sets the mask of the instance to that of the sprite "spr_Round".

I've also used:
mask_index = string(sprites_array[state] + choose(facing, "R", "L"));

and I get the same error. Very confused here....

Also, what does EvanSki mean F1 to pay respects mean?

Thanks,

joeb
 

FrostyCat

Redemption Seeker
I have an array of strings, sprites_array[x] for a character which has both left and right animations. I have an enum array of "states", i.e. IDLE, WALK, ATTACK that I use to get the correct base name of the sprite and I am trying to get to the mask_index for that spite and I am using the following code:

sprite_index = string(sprites_array[state] + choose(facing, "R", "L"));
mask_index = sprite_index;
I get an error can't convert string to integer. I may be reading the docs wrong but don't you set mask index equal to a string. From the manual:

Example:
mask_index = spr_Round;

The above code sets the mask of the instance to that of the sprite "spr_Round".
Resource IDs are not strings, stop treating them like one.

Go into GMS 2 now and run this:
Code:
show_message(spr_Round);
You will see a number, not spr_Round. This is conclusive proof that sprite IDs are not strings.

To convert a string into a sprite ID, use asset_get_index().
Code:
sprite_index = asset_get_index(sprites_array[state] + choose(facing, "R", "L"));
Also, what does EvanSki mean F1 to pay respects mean?
He means that pressing the F1 key also brings up the Manual. That's the traditional key for bringing up documentation in Windows programs.
 
Top