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

I want to execute a script on a certain conditon

P

prithvidiamond

Guest
Hello,

Can someone tell me how to execute a script when a certain condition is fulfilled?

All answers are appreciated,

prithvidiamond
 

jo-thijs

Member
I'm not entirely sure what you mean.
Do you want a script to execute as soon as a certain condition is met
or do you want it to execute at a specific location, only if a certain condition is met?

Also, do you want it as code or as DnD?

In case you want it as code and at a specific location:
Code:
if condition
    script_name(argument_list);
 
P

prithvidiamond

Guest
I want a script to execute as soon as a certain condition is met.

Hope the above helps!
 

jo-thijs

Member
Ok then, what is the condition and how immediate must the script be executed?
Does it suffice if it is executed in the same step as the step in which the condition is met
or does it really need to be executed as soon as the condition is met?
 

NeoShade

Member
Help us help you by telling us more about what you're trying to achieve. Nobody's going to steal your ideas, so give us some more information and maybe we can help out.
 

Xer0botXer0

Senpai
Code:
if dinner == "ready"
{
scr_go_eat()
}
Whoops I see this has already been answered.

Help us help you by telling us more about what you're trying to achieve. Nobody's going to steal your ideas, so give us some more information and maybe we can help out.
Unless he's figured out how to raise the dead..
 
P

prithvidiamond

Guest
var inst;

if (mouse_check_button_pressed(mb_left) and inst = collision_point(mouse_x, mouse_y, obj_2, true, true));
{
points += 1

scr_draw_obj1();
scr_draw_obj2();

}

Here is the code and is it right?
 
A

Aura

Guest
No, it isn't. You are including an assigning in an expression which isn't possible in GML, so it should be collision_point(mouse_x, mouse_y, obj_2, true, true) != noone. That should let GM:S know that an instance has been clicked. If you want to store the ID, do it before using it in the IF statement.
 
P

prithvidiamond

Guest
It still keeps popping up as a mal-informed statement!

Why?
 

Xer0botXer0

Senpai
Please copy and paste the error message you are getting.

The and also doesn't exist, there's syntax for it.

https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml language overview/401_04_expressions.html

&&, ||, ^^ (and, or and xor) - Combine Boolean values to give either true or false. If any of the following examples resolves to true then the code would be run:
The page says boolean values how ever it may be values of any data type I believe.




Code:
if (mouse_check_button_pressed(mb_left))
{
if (collision_point(mouse_x, mouse_y, obj_2, true, true))
{
points += 1;
scr_draw_obj1();
scr_draw_obj2();
}
}
Or

Code:
if (mouse_check_button_pressed(mb_left)) && (collision_point(mouse_x, mouse_y, obj_2, true, true)
{
points += 1;
scr_draw_obj1();
scr_draw_obj2();
}
There's no need to store instance_points return value into a variable in this case.
 
Last edited:
A

Aura

Guest
Please post the IF statement in its current state. And make sure that you are not putting a semi-colon at the end of IF statement.
 

jo-thijs

Member
@Xer0botXer0,
In GameMaker using and instead of && is actually valid syntax,
though it is good practice to use &&, as it is required in many other programming languages and it is more readable in my opinion.

The boolean operators do accept more than only booleans, but they don't accept any data type.
You should only fetch them numbers and not arrays or strings or whatever else.

@prithvidiamond,
I'm glad it's working!
Though I have no idea what suggestion made it work or even what it is exactly.

Anyway, please tag this topic as SOLVED.
 
Top