GameMaker SOVLED Creating a creation code for generated object

S

Shizuky

Guest
Hi,
I wanted my game , when a Player coems to certain spot to create warp which will port him somewhere, but I need to create a creation code when it spawns. How could I code , that when creating that warp it will be created with creation code?

I used this code to create Warp:
var p = instance_create_layer(480,672,"Instances_3",objWarp)
p.image_xscale = 3;
p.image_yscale = 3;


and I want it to be created with this creation code:
targetRoom = Room5
targetX = 480
targetY = 672
 

flerpyderp

Member
Simple, just use the p variable you already made to refer to the created instance and give it those variables.

Code:
var p = instance_create_layer(480,672,"Instances_3",objWarp)
p.image_xscale = 3;
p.image_yscale = 3;
p.targetRoom = Room5
p.targetX = 480
p.targetY = 672
Alternatively, you could use a with statement.

Code:
var p = instance_create_layer(480,672,"Instances_3",objWarp)

with (p)
{
    image_xscale = 3;
    image_yscale = 3;
    targetRoom = Room5
    targetX = 480
    targetY = 672
}
 

TheouAegis

Member
To further elaborate on this, you should have a global array, ds_list, or ds_grid which holds all the room and coordinates. Then when the warp is created, you find the current room/stage/level/whatever in the array/list/grid/whatever and then fetch the targetRoom, targetX, and targetY.
 
Top