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

Windows Collect all the coins to move to the next lvl

N

Northernlightifly

Guest
[SOLVED]

Hello!

I'm making a platform game, in order to move to the next level the player has to collect all the coins. Once that is done the player go to the goal flag and move on to the next level. I'm having problem with making my code to work.

This code has an error in it, "Unexpected symbol in expression"

Code:
if ((!instance_exists(obj_gold_coin)) && (obj_silver_coin))) {
This is the entire code, which I made through making a "Create event"

Code:
open = false;

if (open == true){
     room_goto(lvl_2);
}

if ((!instance_exists(obj_gold_coin)) && (obj_silver_coin))) {
      open = true;
}
Thank you in advance!
 
Last edited by a moderator:
E

Edwin

Guest
Wrong coding. You can not use "and" or "&&", "or" or "||" symbols while setting the arguments in functions.

You shoud do this:
Code:
if (!instance_exists(obj_golden_coin) && !instance_exists(obj_silver_coin)) {
    room_goto(rm_whatever);
}
You can set only 1 object to check...

...but that doesn't mean that you can not create your own script that allows you to check more than 1 argument. Remember that you can upgrade this engine to make it more convinient for yourself and everyone.
 
Last edited:
N

Northernlightifly

Guest
Wrong coding. You can not use "and" or "&&", "or" or "||" symbols while setting the arguments in functions.

You shoud do this:
Code:
if (!instance_exists(obj_golden_coin) && !instance_exists(obj_silver_coin)) {
    room_goto(rm_whatever);
}
You can set only 1 object to check...

...but that doesn't mean that you can not create your own script that allows you to check more than 1 argument. Remember that you can upgrade this engine to make it more convinient for yourself and everyone.
Thank you! But whenever I pass the flag nothing happens...but yes I update my gamemaker file and try again :)
 
E

Edwin

Guest
Thank you! But whenever I pass the flag nothing happens...but yes I update my gamemaker file and try again :)
You are checking the flag before the flag is set to true.

You are checking the coins existence only when your object is created. That means it will never perform again. You shoud use Step event to check their existence every step (game frames).

Create event (performed when created):
Code:
open = false;
Step event (performed every frame):
Code:
if (!instance_exists(obj_gold_coin) && !instance_exists(obj_silver_coin)) {
     open = true;
}

if (open == true) {
    room_goto(lvl_2);
}
 
N

Northernlightifly

Guest
You are checking the flag before the flag is set to true.

You are checking the coins existence only when your object is created. That means it will never perform again. You shoud use Step event to check their existence every step (game frames).

Create event (performed when created):
Code:
open = false;
Step event (performed every frame):
Code:
if (!instance_exists(obj_gold_coin) && !instance_exists(obj_silver_coin)) {
     open = true;
}

if (open == true) {
    room_goto(lvl_2);
}
Okay thank you! I get this error after I collect all the coins..


 
E

Edwin

Guest
Also, don't leave this thread "unsolved". Put [SOLVED] right before this threads title so people can find this topic and take it as the answer to their question or as the solution to their problem.
 
Top