• 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 Change the image_xscale of a specific object?

B

Bokkie2988

Guest
Hello,

How would I adress a specific object and change its image_xscale?
I tried using this :
Code:
var weapon = instance_create_layer(x+8,y-3,"Player",oEnemyPistol);

if (image_xscale = -1) weapon.image_xscale = -1;
But the game gives a error code saying
Code:
local variable weapon(100002, -2147483648) not set before reading it.
Can anyone help?
 
J

Jonar

Guest
Try making weapon an instance variable instead of a local variable. If that doesn’t work then I have no idea.
 

samspade

Member
If that code is actually together like that (in other words one line after the other in the same event) it should work if the instance_create_layer works. So one possibility is that it is not working - perhaps because the layer doesn't exist. If those two pieces of code are not together, or if you are using the

Code:
if (image_xscale = -1) weapon.image_xscale = -1;
line elsewhere then because you have made weapon a local variable it will cease to exist after that event/script that it is being called in.

I'd run this with the debugger turned on and see what the variable actually holds. See:Debugging with GMS2.
 
C

Cotcho

Guest
I would also fix the operator you are using from an assignment “=“ operator to the comparison “==“ in your if statement.
 
Hello,

How would I adress a specific object and change its image_xscale?
I tried using this :
Code:
var weapon = instance_create_layer(x+8,y-3,"Player",oEnemyPistol);

if (image_xscale = -1) weapon.image_xscale = -1;
But the game gives a error code saying
Code:
local variable weapon(100002, -2147483648) not set before reading it.
Can anyone help?
What you may want to try is this:
Code:
//Using the "with" block directly addresses the object being created.
with(instance_create_layer(x + 8, y - 3, "Player", oEnemyPistol){image_xscale = -1;})
 
B

Bokkie2988

Guest
If that code is actually together like that (in other words one line after the other in the same event) it should work if the instance_create_layer works. So one possibility is that it is not working - perhaps because the layer doesn't exist. If those two pieces of code are not together, or if you are using the

Code:
if (image_xscale = -1) weapon.image_xscale = -1;
line elsewhere then because you have made weapon a local variable it will cease to exist after that event/script that it is being called in.

I'd run this with the debugger turned on and see what the variable actually holds. See:Debugging with GMS2.
Thanks to everyone for helping. The problem was that the 2 lines of code were not directly after eachother, there was some other code between it. Apperently that's not allowed in GMS2. Thanks!
 

Relic

Member
It is, as long as the local referenced variable ‘weapon’ still exists and is an instance id.
 
Thanks to everyone for helping. The problem was that the 2 lines of code were not directly after eachother, there was some other code between it. Apperently that's not allowed in GMS2. Thanks!
Out of curiosity, what was the code in between? It doesn't sound like your solution was an actual solution.
 
Top