• 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!

GML object_get_sprite doenst work

P

PilsZuiger

Guest
Hi I wrote this code voor a topography game:

Code:
currentquestion = object_get_sprite(obj_topoquest);

if((currentquestion == argument0 ||currentquestion ==  argument1) && global.vraagtopo <9){
ding  = random_range(0, 23);


switch(ding){
case 0: with(obj_topoquest) sprite_index = spr_drenthevr1
case 1: with(obj_topoquest) sprite_index = spr_drenthevr2;
case 2: with(obj_topoquest) sprite_index = spr_noordhollandvr1;
case 3: with(obj_topoquest) sprite_index = spr_noordhollandvr2;
case 4: with(obj_topoquest) sprite_index = spr_zuidhollandvr1;       
case 5: with(obj_topoquest) sprite_index = spr_zuidhollandvr2;
case 6: with(obj_topoquest) sprite_index = spr_frieslandvr1;
case 7: with(obj_topoquest) sprite_index = spr_frieslandvr2;
case 8: with(obj_topoquest) sprite_index = spr_groningenvr1;
case 9: with(obj_topoquest) sprite_index = spr_groningenvr2;
case 10: with(obj_topoquest) sprite_index = spr_brabantvr1;
case 11: with(obj_topoquest) sprite_index = spr_brabantvr2;
case 12: with(obj_topoquest) sprite_index = spr_limburgvr1;
case 13: with(obj_topoquest) sprite_index = spr_limburgvr2;
case 14: with(obj_topoquest) sprite_index = spr_flevolandvr1;
case 15: with(obj_topoquest) sprite_index = spr_flevolandvr2;
case 16: with(obj_topoquest) sprite_index = spr_overijsselvr1;
case 17: with(obj_topoquest) sprite_index = spr_overijsselvr2;
case 18: with(obj_topoquest) sprite_index = spr_utrechtvr1;
case 19: with(obj_topoquest) sprite_index = spr_utrechtvr2;
case 20: with(obj_topoquest) sprite_index = spr_gelderlandvr1;
case 21: with(obj_topoquest) sprite_index = spr_gelderlandvr2;
case 22: with(obj_topoquest) sprite_index = spr_zeelandvr1;
case 23: with(obj_topoquest) sprite_index = spr_zeelandvr2;
}
global.vraagtopo += 1;
}
if(global.vraagtopo == 9 || global.vraagtopo >9){
//insert here what should happen once the game is over
}
else{
//insert here what should happen if player's anwser is wrong
sound_play(snd_ohno);
}
The player should click on the correct answer. If the player clicks an answer this script gets executed. The argument0 & argument1 are the questions matching the answer the player clicked. So in the first if statement it checks if the answer is correct and if it is it randomly changes the question sprite and adds 1 onto the var that checks at which question the player is.

In the second if statement it check wether the player is at the final question or not. In the else it says what should happen if the answer of the player is wrong.

But it looks like both of the if statements arent triggers at all... How can I fix it what could be wrong?
 
P

PilsZuiger

Guest
You'll need to do both things to get it to work. Add the breaks and change random to irandom.
we changed that, so the first questions works now but as soon as we click on the right answer it starts executing the else aswell.....
 
Your else{} statement is in the wrong place.

With a bit of reformatting, we can see that the else statement will always be run if you are not at the last question yet.
Code:
currentquestion = object_get_sprite(obj_topoquest);

if ((currentquestion == argument0 ||currentquestion ==  argument1) && global.vraagtopo <9)
{
    ding  = random_range(0, 23);

    switch(ding)
    {
        case 0: with(obj_topoquest) sprite_index = spr_drenthevr1
        //deleted for example purposes
        case 23: with(obj_topoquest) sprite_index = spr_zeelandvr2;
    }
    global.vraagtopo += 1;
}

// THIS IS A NEW IF STATEMENT - It's independent from the previous if(), so will run everytime.

if (global.vraagtopo == 9 || global.vraagtopo >9)
{
    //insert here what should happen once the game is over
}
else
{
    //insert here what should happen if player's anwser is wrong
    sound_play(snd_ohno);
}
Your code should be structured like this :
Code:
currentquestion = object_get_sprite(obj_topoquest);

if ((currentquestion == argument0 ||currentquestion ==  argument1) && global.vraagtopo <9)
{
     // IF ANSWER IS CORRECT
    ding  = random_range(0, 23);

    switch(ding)
    {
        case 0: with(obj_topoquest) sprite_index = spr_drenthevr1
        //deleted for example purposes
        case 23: with(obj_topoquest) sprite_index = spr_zeelandvr2;
    }
    global.vraagtopo += 1;
}
else
{
    // IF ANSWER IS WRONG
    //insert here what should happen if player's anwser is wrong
    sound_play(snd_ohno);
}

if (global.vraagtopo == 9 || global.vraagtopo >9)
{
    //insert here what should happen once the game is over
}
 
Top