Hi there friends! I have a problem with variable propably, well
How to make a variable for each object separately? I have a sprite called “skeleton1” and I have added two objects of this sprite to the map. Now how to make each of these objects individually relative to the player’s position when panning horizontally?
I’m assuming you want to have a variable for both skeletons but with different values?
Like maybe you want to create a variable, like for example, ContestantNumber = 1, then the other one would have ContestantNumber = 2
If that was what you were going for, you could click on each individual instance on the scene. Then look into the object properties and scroll down. You will find the part that says “Instance Variables”. You can set it from there.
Nicely explained. I think this topic is now solved.
yes, that’s right, I’ve reached this stage myself. The problem is that I have no idea what the variable should be, whether it should be a structure or an array or something else, whatever to call it, I’m terribly lost in these variables eh.
Well, it depends on what you’re trying to use the variables for.
If you want to name them and call them in some event,
If it’s stage 1, I want Contestant 1 to stand up. if it’s stage 2 then, I want Contestant 2 to stand up. stage 3… and so on. Here you use number variables.
If suppose you want one to be moving and the other one is not moving, Perhaps use boolean variables, just true or false.
If you want very specific naming stuff. ContestantName = Ghostrider, then you use string variable.
For structure variables, I usually use them when I want to access other sub-variables in one go, like saving the game or something.
I haven’t used array variables yet. But I believe you use them when you need it to have multiple values in one variable. Maybe like, WeaponsOwned = 1, 8, 15, 17
Something like that. But idk, since I really haven’t had a use for it yet.
You did mention about them being relative to player’s position, horizontally. Then I believe you might want to go for number variable and it is equal to their x coordinate.
Or perhaps you want the one nearest to the player to do something, then use boolean. “Pick skeleton1 object closest to player” change variable, SkelNear = true.
But idk. You’re gonna have to be a bit more specific if possible.
As you can see in the photo, there is a player (letter P) between objects 1 and 2. Object number 1 is standing correctly, towards the player, but object number 2 is not. I set the conditions and actions to chew horizontally, but then all objects react even if they are not positioned correctly.
Ah. I believe you will need a for each condition.
I’m not sure how it goes on the mobile, but I think it goes like this,
You go into your event sheet, then long press on an event until other options appear.
Look for “Add”
then “Add for each object”.
Or try to find the “+” sign with a circle, probably beside the “add a comment” button.
It should go something like:
Flip horizontally Skeleton1
This way, it will go through each skeleton instance and will only execute the flip on the one that fulfills the condition of angle to player.
Try something like this. Only a example to learn from-
Yea its work IT!
Thank you soo much friends!
Uhm… just something that I thought I’d mention.
You could make both position checks as subconditions under a single for each condition.
For each instance of Skeleton1:
__The position of Player < … etc.
__Flip horizontally: yes
__The position of Player > … etc.
__Flip horizontally: no
Just, you know. Though still, if it works, it works. Nice.