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

HTML5 instance_create_layer : Problem with HTML5

J

Jackdahack

Guest
Hi,

we are currently designing a small browser game for our company. For this we use GameMaker Studio. We have created a login script so far. After verifying that password and username are correct, the script should create a player object in a predefined space. That´s the Code for that:

room_goto(rm_Spawn);
instance_create_layer(position[0], position[1], "Player", obj_Player);

Now the problem. When we run the project from GML by default, everything works fine. You can register and then log in and an obj_player appears in the room. With the cursor keys the figure jumps 30pixel in the corresponding direction.

But as soon as we put everything on HTML5, the player object disappears as soon as a cursor key is pressed. We once hung an alarm on the obj_player, which also runs. So it seems to be there, but we do not see it anymore :(

Another notoriety: If we place obj_player in advance in GML in the room, everything works fine. So we suspect that it has something to do with the instance_create_layer.

Any idea ??? Or is there an alternative method .
 

Mert

Member
There's one wrong thing with this code and that's where you use instance_create*. This function creates the instance within the current room, not in the next one.

It is a common behaviour that once you switch to another room, your codeflow stops there, anything beyond room_goto.. is not executed(as far as I can tell)

Unless you have a persistent(persistent=true) object, your instance is not in the room where you want it to be.

The quickest solution comes to my mind is creating a global variable and executing instance create in rm_Spawn room's creation code.
Code:
global.position[0] = x;
global.position[1] = y;
Code:
instance_create_layer(global.position[0], global.position[1], "Player", obj_Player);
 
J

Jackdahack

Guest
We did. Now GMS does not create the GameObject. We also created a KeyPressed Event (space = instance_create *) But that too did not work. He does not display a character now.
 

chmod777

Member
Check you're using the last runtime as there are issues with this function in the first 2.2 release.

We have now confirmed all of the following and are preparing a runtime update (likely releasing early next week) to include:

https://bugs.yoyogames.com/view.php?id=30064 - HTML5: instance_create_layer() no longer works
https://bugs.yoyogames.com/view.php?id=30068 - Windows: Crash when using get_string_async() and get_integer_async()
https://bugs.yoyogames.com/view.php?id=30067 - Android: Null pointer audio device crash when resuming games from sleep state in 2.2.0
https://bugs.yoyogames.com/view.php?id=29655 - Build iOS: Unable to build for YYC in Xcode 10 as we use angle brackets to define headers, which is no longer supported
 
J

Jackdahack

Guest
OK, updated.thx for the info :)

But still...we created 2 Rooms. In both Rooms we made a "create Event" in the obj_room1controller. We said "room_goto(room1)" an in the 2nd room we said "instance_create_layer (0,0,0,obj_player)" in the Create Event of obj_room2controller.

It doesn´t work BUT if we put instance_create_layer (0,0,0,obj_player) into the obj_room1controller it works(in room1). So somehow we have probs when switching a room.
 
Top