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

object with variables from script?

C

corwin22

Guest
I have a script that is supposed to create an object with a few variables but it doesn't work I have tried using 'with' but it won't work?
//scr_orb(Health,color,speed)
// using this will create an entire row at the top!

orb = (instance_create_layer(32,32,"Enemy",obj_orb))
with (orb) {
Health = argument0
Color = argument1
spd = room_speed * argument2
}
 
C

corwin22

Guest
I changed the variable but it still doesn't get the 'spd' variable from the script.
 
C

corwin22

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

Variable obj_orb.spd(100021, -2147483648) not set before reading it.
at gml_Object_obj_orb_Create_0 (line 2) - alarm[0] = spd
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_orb_Create_0 (line 2)
called from - gml_Script_scr_orb (line 4) - orb = (instance_create_layer(32,32,"Enemy",obj_orb))
called from - gml_Object_obj_playGui_Create_0 (line 1) - scr_orb(4,4,4)
 

FrostyCat

Redemption Seeker
Create events run at the point of the call to instance_create_layer(), the code in your with block won't make it in on time.

Create a blank object called xobj_egg, create an instance of it and load it with variables, then change it to the actual object type once it's ready:
Code:
with (instance_create_layer(32, 32, "Enemy", xobj_egg)) {
  Health = argument0;
  Color = argument1;
  spd = room_speed * argument2;
  instance_change(obj_orb, true);
}
This is a standard pattern demonstrated in this article.
 
Top