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

GameMaker Studio 2 code

S

Stefan Tabakov

Guest
So I'm relevantly new to GameMaker Studio, but I've been having trouble with these few lines of code. They work properly in GameMaker 1.4, but not in GameMaker 2. Here they are:

This is an alarm event:
instance_create (random_range(16, room_width-16), -16, o_enemy_one);
alarm[0] = random_range(room_speed*.5, room_speed*2);

And this is a create event to the same object:
alarm[0] = room_speed*3;

There is no instance_create function in GameMaker Studio 2. If you could help me I'd be very grateful
 
S

Stefan Tabakov

Guest
In GMS2 you need to use instance_create_layer or instance_create_depth
I tried using instance_create_layer but if i try and do ''instance_create_layer (random_range(16, room_width-16), -16, o_enemy_one);'' It will give me a Syntax error and if i try doing ''instance_create_layer (random_range(16, room_width-16), -16, o_enemy_one, s_enemy_one);'' (because it requires 4 arguments) it will give me an error when the event occurs during the game:

############################################################################################
ERROR in
action number 1
of Alarm Event for alarm 0
for object o_enemy_spawner:

Creating instance for non-existing object: 4
at gml_Object_o_enemy_spawner_Alarm_0 (line 2) - instance_create_layer (random_range(16, room_width-16), -16, o_enemy_one, s_enemy_one);
############################################################################################
 

rIKmAN

Member
I tried using instance_create_layer but if i try and do ''instance_create_layer (random_range(16, room_width-16), -16, o_enemy_one);'' It will give me a Syntax error and if i try doing ''instance_create_layer (random_range(16, room_width-16), -16, o_enemy_one, s_enemy_one);'' (because it requires 4 arguments) it will give me an error when the event occurs during the game:

############################################################################################
ERROR in
action number 1
of Alarm Event for alarm 0
for object o_enemy_spawner:

Creating instance for non-existing object: 4
at gml_Object_o_enemy_spawner_Alarm_0 (line 2) - instance_create_layer (random_range(16, room_width-16), -16, o_enemy_one, s_enemy_one);
############################################################################################
I'm not sure what your code looks like, but from that error message it's saying the object you are trying to pass as an argument doesn't exist.

From the manual:
---

Syntax:
instance_create_layer(x, y, layer_id, obj);

Argument Description
x:
The x position the object will be created at.
y: The y position the object will be created at.
layer_id: The layer ID (or name) to assign the created instance to.
obj: The object index of the object to create an instance of.

---

Are you meant to be passing in -16 as the y argument?
Is o_enemy_one a valid layer_id?
Is s_enemy_one a valid object?

Have you tried importing your 1.4 project into GMS2?
It will create compatibility scripts which change deprecated function calls to valid GMS2 function calls (ie. instance_create() to instance_create_layer() etc)
 
S

Stefan Tabakov

Guest
I'm not sure what your code looks like, but from that error message it's saying the object you are trying to pass as an argument doesn't exist.

From the manual:
---

Syntax:
instance_create_layer(x, y, layer_id, obj);

Argument Description
x:
The x position the object will be created at.
y: The y position the object will be created at.
layer_id: The layer ID (or name) to assign the created instance to.
obj: The object index of the object to create an instance of.

---

Are you meant to be passing in -16 as the y argument?
Is o_enemy_one a valid layer_id?
Is s_enemy_one a valid object?

Have you tried importing your 1.4 project into GMS2?
It will create compatibility scripts which change deprecated function calls to valid GMS2 function calls (ie. instance_create() to instance_create_layer() etc)
The Thing is I've been watching a beginner course about GMS but its on 1.4 and I'm trying to do it on GMS2. But yes everything seems like it should work but then it doesn't.
 

rIKmAN

Member
The Thing is I've been watching a beginner course about GMS but its on 1.4 and I'm trying to do it on GMS2. But yes everything seems like it should work but then it doesn't.
If you are comfortable enough with GML to convert the deprecated functions from 1.4 <> 2.0 yourself then you need to do it as you go along with the tutorial, typing some 1.4 code directly into GMS2 won't work as you are finding out because some of the functions have changed.

There is a list of the changes somewhere either here on the forum or on the yoyo website in an article, have a mooch around Google and the search on here.

If you are just learning GM and have access to 1.4 (I think there is a free version) then use that to do the tutorial, and once it's working "import" it into GMS2 and it will create compatibility scripts to "bridge the gap" so to speak and convert all the old 1.4 functions into working 2.0 functions automatically so it should all just work.
 
S

Stefan Tabakov

Guest
If you are comfortable enough with GML to convert the deprecated functions from 1.4 <> 2.0 yourself then you need to do it as you go along with the tutorial, typing some 1.4 code directly into GMS2 won't work as you are finding out because some of the functions have changed.

There is a list of the changes somewhere either here on the forum or on the yoyo website in an article, have a mooch around Google and the search on here.

If you are just learning GM and have access to 1.4 (I think there is a free version) then use that to do the tutorial, and once it's working "import" it into GMS2 and it will create compatibility scripts to "bridge the gap" so to speak and convert all the old 1.4 functions into working 2.0 functions automatically so it should all just work.
Ok! Thank you very much!
 

Perseus

Not Medusa
Forum Staff
Moderator
Here's the list(s) that @rIKmAN was talking about:

http://help.yoyogames.com/hc/en-us/articles/231539867-GameMaker-Studio-2-New-Functions-List
http://help.yoyogames.com/hc/en-us/articles/231738328-GameMaker-Studio-2-Obsolete-Function-List

Either way, I won't recommend using a GM:S 1.4 tutorial for GMS 2. Try using the built-in tutorials, or if you're comfortable using video, search a bit on YouTube -- there's already a decent number of tutorials. There're a number of tutorials in the GMS 2 Beta and the Tutorials forums.
 

Coded Games

Member
You guys probably would have solved this in 3 seconds by just reading the documents of instance_create_layer().

You had this: instance_create_layer(random_range(16, room_width-16), -16, o_enemy_one, s_enemy_one);

instance_create_layer should be formatted like this: instance_create_layer(x, y, layer, object)

Layers are a new feature of GMS2 so since you're following a tutorial for GMS1 you won't have any created so you will want to use instance_create_depth instead.

The parameters for that is instance_create_depth(x, y, depth, object);

Since at this point depth really doesn't matter you can just set that to be any number you want. 0 makes things easy.
 
Top