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

Shop System Part 3

W

WolfYouTube

Guest
How do I change my player when the player buys something in the shop? When I do obj_Player.sprite_index = spr_Green it gives me an error so help.

Thanks
WolfYt
 
What object are you calling that from? I'm going to assume this code is in obj_shop or something similar.
The obj_Player in your code may not be targeting a specific instance (the player in the room), but instead the actual object. I would try using the with command to get the instance.
Code:
with (obj_Player) {
    sprite_index = spr_Green;
}
Again, this is only if you're calling that from a different object. If the player itself is using that code, make sure it doesn't reference the object like that, and instead just use
Code:
sprite_index = spr_Green
Let me know if it helps
 

Fredrik

Member
If you're calling the code from the object "obj_Player" you're probably getting an error because you're using "obj_Player.sprite_index" and not just "sprite_index" as you won't need the object to referr to itself. Otherwide I think you'd have to post more of your code.
 
W

WolfYouTube

Guest
What object are you calling that from? I'm going to assume this code is in obj_shop or something similar.
The obj_Player in your code may not be targeting a specific instance (the player in the room), but instead the actual object. I would try using the with command to get the instance.
Code:
with (obj_Player) {
    sprite_index = spr_Green;
}
Again, this is only if you're calling that from a different object. If the player itself is using that code, make sure it doesn't reference the object like that, and instead just use
Code:
sprite_index = spr_Green
Let me know if it helps
I made a room for the shop is that the best way?
 
Sorry, apparently I didn't read the first post all the way. You said it gave you an error? Mind showing me what error you are getting? The code seems like it would work so there must be something else going wrong
 
Top