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

Variables not working.

K

k1nb

Guest
While testing my games, fixing and etc., i came up with one fatal error when launching the game.

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object obj_enemy:

Variable obj_enemy.scr_enemy_idle(100012, -2147483648) not set before reading it.
at gml_Object_obj_enemy_CreateEvent_1 (line 4) - state = scr_enemy_idle;
############################################################################################

Scripts and Code that were related with this error is (code included)

Obj_enemy
state_text = 'idle';
state = scr_enemy_idle;
bef_div_vision_range = random(200)
vision_range = (bef_div_vision_range div 1)
bef_div_attack_range = random(30)
attack_range = (bef_div_attack_range div 1)
spd = 5

scr_enemy_idle
///scr_enemy_idle
state_text = 'idle'
var dis=point_distance(x,y,playerx,playery)
if (dis<=sight_range) {
state = scr_enemy_chase;
}

Im new to GML and just trying out on making games, so sorry for my stupidity.

and it may take me some time to respond.
 
C

Christian

Guest
You didn't define scr_enemy_idle anywhere.
What is scr_enemy_idle supposed to equal? I see you defined state, but not scr_enemy_idle.

If you made a script called scr_enemy_idle, then you need to execute it as such. Simply using scr_enemy_idle(); will do (Unless you have arguments in the script).
 
C

Christian

Guest
point_distance(x,y,playerx,playery)

should be

point_distance(x,y,player.x,player.y)
no?
If playerx and playery are specifically defined, no it doesn't need to be the latter. If they aren't defined, then it should be that.
 
K

k1nb

Guest
You didn't define scr_enemy_idle anywhere.
What is scr_enemy_idle supposed to equal? I see you defined state, but not scr_enemy_idle.

If you made a script called scr_enemy_idle, then you need to execute it as such. Simply using scr_enemy_idle(); will do (Unless you have arguments in the script).
Ah,i noticed that you name the scripts on the top right bar when editing scripts, i thought it was by using ///scriptname , i'm sorry.

point_distance(x,y,playerx,playery)

should be

point_distance(x,y,player.x,player.y)
no?
I defined my player's current x and y to be playerx and playery, i didnt know you could use it like that.

Thank you guys for all the replys.
 
C

Christian

Guest
Ah,i noticed that you name the scripts on the top right bar when editing scripts, i thought it was by using ///scriptname , i'm sorry.
.
No worries. Glad you were able to get it up and running. When people use /// Before the first line of a script, they are giving it a title/tooltip comment. This way they can see what it's supposed to do just by hovering over it.
// are regular comments
and /* This also counts as a regular comment */

However Gamemaker will never do anything with comments. It ignores any comment to help you organize your code better.
 
Top