How to reset self.time to 0?
hamzawesome
Member, PRO Posts: 30
Apparently there is no way to do this, but I have a game where an actor revolves around another actor whenever the screen is pressed. But for some reason, if I wait a few seconds and then touch the screen, the actor jumps ahead and suddenly appears elsewhere around the actor it's revolving around, and then it begins revolving at its normal speed. I believe the reason for this is the self.time for the actor that revolves, how do I find a way to make it reset?
Comments
You cannot reset self.Time. You can, however, make your self self attribute and increment it continuously. Hook up that newly created self attribute into your equation.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Thanks so much for your reply. Since I'm still pretty new to GameSalad, do you think you could explain how to do all that, step-by-step? I hate to ask this, but if you can then I'd greatly appreciate it! Thanks again!
When condition X is met . .
Destroy
Spawn (this actor)
This might not be viable in every situation (depending on how your actor works) otherwise it's a quick and clean way to (effectively) reset self.time.
Self.time is simply a measure of the time that has elapsed since the actor appeared on the scene.
Don't hate to ask !! Keep asking, the more the better, it's the quickest way to absorb this stuff !
Thanks for your help! In my case, I can't actually destroy the actor then respawn it, since I would have to have it respawn immediately, in the exact same place where it was destroyed. I just want to know if there is a way to equate self.time to an attribute, and then reset that attribute so that it would be like resetting the self.time in a way. Is there a way to do that?
I'm not sure I understand what you are saying, why would destroying and respawning an actor be an issue (with your particular project) ?
Of course ! Self.time is simply the time that has elapsed since the actor appeared in the scene, it is measured in seconds, so anything that counts up in seconds would be functionally equivalent to self.time.
This is how i "reset" self.time.
Create a new self attribute (real) and call it timestamp.
Now, when you want to use self.time on a rule/behavior, use "self.time-self.timestamp".
If you want to "reset" self.time, just use "change attribute self.timestamp to self.time".
Hope this helps!
Mental Donkey Games
Website - Facebook - Twitter
Why are you just not using a timer?
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Destroying and respawning the actor would be an issue because the actor is revolving around a planet, and once it is destroyed, I would need it to respawn right where it was destroyed. It can't look like it was destroyed. How do I respawn an actor in the exact same spot where it was just destroyed?
In the spawn behavior, put both cordinates and direction to 0, and relatve to actor.
Mental Donkey Games
Website - Facebook - Twitter
Simply use the Spawn behaviour with its default values.
I appreciate your help, but that causes it to move in a very stunted motion, rather than smoothly revolving around the planet.
Is there no way to just have an actor that revolves around another planet move right where it last stopped moving? Rather than just let it jump ahead and then start revolving? I was looking at this other thread (that you also posted in, coincidentally) but apparently the OP couldn't find a solution to that either: https://forums.gamesalad.com/discussion/63667/possible-to-use-the-move-behaviour-to-move-in-a-circle
Sure, but you've said you want it to reset to 0 rather than where it last stopped moving, unless where is last stopped moving is always 0 ?
And also you've not explained anything about how your code works, or what it is - all we have is that one actor is revolving (orbiting?) another - so people are basically guessing at what's going on, how it might be set up, what rules and behaviours you might be using and so on, which is always a very slow way to resolve an issue, the information people need is on your monitor, but without seeing it we can only guess.
This can turn a simple question into a long thread that goes on for days or weeks with lots of dead-end tangents and often no real resolution.
I see it like this, here are two approaches to resolving a problem, to me approach B is much better, but approach A is surprisingly common:
A: I am adding up two numbers that I need to come to 802, but I keep getting 1600, anyone got a solution ?
B: I am adding up two numbers that I need to come to 802, the sum is 800 + 2, but I keep getting 1600, anyone got a solution ?
(example B, includes the 'code' (the sum is 800 + 2) from which we can quickly guess that the person asking the question has probably used a multiply sign where he thinks he has a plus sign (800 x 2 =1600) . . . with example A you are left to guess what the 'code' might be, there is no obvious way to move forward with A other than lots of random-ish guesses).
Sure, it's all possible, but we'd need to see what we are working with, I could spend 10 minutes working something out for you, only to be told that it won't work with your code, someone else then tries something else, same deal, it won't work because of X, Y or Z, then I'll try controlling the orbiting actor with X only to be told this won't work because you are using ABC to change the speed . . . and so on . .
Sorry for not being more clear. In my game, the actor (named Orbi) orbits around a planet while the screen is being touched. Here is a screenshot for the rules I've placed for Orbi:
Here are the attributes I have for the planet that Orbi orbits:
Hopefully it's more clear now. I believe the problem is that I'm using the Time attribute for Orbi (self.time) to orbit the Planet. While he does orbit the planet at the exact speed I want him to while I'm pressing, whenever I delay after pressing (i.e. if I'm not pressing the screen, then wait a few seconds, and press the screen again) he just jumps ahead, suddenly appearing on another spot around the planet, and starts moving from there. The longer I wait before touching the screen again, the farther ahead he appears before starting to move. This is what I need help with--I don't want him to jump ahead and only move from where he left off. I can provide a .gif of this if it needs further clarification.
No problem, thanks for the rules, that's much clearer now ! I'm going to guess my way through the expression boxes (they are familiar enough expressions) but for future reference it's always more useful to show what is in these expression boxes, you can simply click on the 'e' to open them before taking your screenshot, otherwise you are asking people to say what is wrong with this sum: 55*400+9[...the rest of the sum is cut off]
Back in a minute . . . .
Constrain X to 150 * cos (self.time *100%360)+Game.Planet X position
Constrain Y to 150 * sin (self.time *100%360) +Game.Planet Y position
Constrain R to V2A (some hidden stuff)
Ok, first you don't really need the modulus bit in the angle cos and sin are operating on, (the %360 bit) you can loose that . . . so . . .
Constrain X to 150 * cos (self.time * 100 )+Game.Planet X position
Constrain Y to 150 * sin (self.time * 100 ) +Game.Planet Y position
Constrain R to V2A (some hidden stuff)
. . . . we need to dump the self.time as it's not useful here . . . .
Constrain X to 150 * cos (some angle value)+Game.Planet X position
Constrain Y to 150 * sin (some angle value) +Game.Planet Y position
Constrain R to V2A (some hidden stuff)
. . . . and use the actor's own rotation rather than the game's clock to slowly increase the angle . . . so . . .
Constrain X to 150 * cos (rotation)+Game.Planet X position
Constrain Y to 150 * sin (rotation ) +Game.Planet Y position
Constrain R to V2A (some hidden stuff)
. . . . then we can dump the Rotation constrain and replace it with a rotate behaviour which will be our controller . . .
Constrain X to 150 * cos (rotation)+Game.Planet X position
Constrain Y to 150 * sin (rotation ) +Game.Planet Y position
Rotate - direction CCW / Speed 100
. . . now you can wrap all this in your touch rule . . . so . .
When touch is pressed:
--Rotate - direction CCW / Speed 100
--Constrain X to 150 * cos (rotation)+Game.Planet X position
--Constrain Y to 150 * sin (rotation ) +Game.Planet Y position
. . . . Just going to check this works, back in a minute . . .
Yep, seems to work just fine, I'm not 100% sure why you have 'when touch is pressed + when touch is outside' . . . I suspect you can dump both of those and use 'when mouse button is down' (mouse button is = touch on a mobile device).
That appears to have fixed it, thank you very much for all your help!