GML Can you help with these problems I have?

COCOAMA

Member
My problems are;
1 - How does indexes work? (for sprites & sounds)
2 - How can I check if one sprite has been set for an object? (with "if" or "with" idk)
3 - How can I check if one of three objects exists and do a thing?
GML:
if instance_exists (object){
sound_play(sound)}
I don't want the sounds to stack up because there are three objects for that sound but I just wanna play it once and I didn't just play it because the objects don't have to be in the room and it wouldn't make any sense)
 
Last edited:

Roldy

Member
The manual should tell you all you need to know. Use it : https://docs2.yoyogames.com/source/_build/index.html


Here are sprites:


In the GMS IDE you have list of resources. Each resource will be assigned a number, an index. In GML you use the sprites name to reference its index. e.g. you have a sprite named "my_sprite" you can just write "my_sprite" in GML as its index.

Each instance will have a sprite_index built in variable: https://docs2.yoyogames.com/source/...nstances/instance_variables/sprite_index.html

You can check or set the sprite being used with this variable:

GML:
if (sprite_index == my_sprite) {  // If my instance is currently using 'my_sprite'
    sprite_index = some_other_sprite; // Change the sprite index to the sprite called 'some_other_sprite'
}
There are a number of instance variables for sprites:
Get to know each one.
 
You can use instance exists multiple times in an if statement to determine if multiple instance exists (make sure you are using && correctly). Also, I can tell by the way you are phrasing your questions that you definitely need to learn what the difference between objects and instances is. You can also check to see if a specific sound is already playing using the audio_is_playing() function. Finally, if you only want the sound to play once, make sure you learn how to restrict unwanted repetition with flags.
 

COCOAMA

Member
You can use instance exists multiple times in an if statement to determine if multiple instance exists (make sure you are using && correctly). Also, I can tell by the way you are phrasing your questions that you definitely need to learn what the difference between objects and instances is. You can also check to see if a specific sound is already playing using the audio_is_playing() function. Finally, if you only want the sound to play once, make sure you learn how to restrict unwanted repetition with flags.
thank you so much
 
Top