Hey, I'm starter with gamesalad and I need help for a project with who I can't carry on.
warloparthur@gmail.com
Member Posts: 23
in Help Wanted
I started a project 3 days ago and I'm blocked because of a problem I can't resolve. I'm blocked with this script: I want an actor to move up and down constantly an with the same x value and a random y value and also a random speed. So I made a loop with 1 max loop per frame --> bahavior=move to x=500 y=random (58 to 264) and with a speed random (100 to 500) and it doesn't work, test it on one of your projects you will see, so how can I make this work or is there another way to make an actor move up and down constantly ?
Comments
I do it this way
Create an integer self attribute call it what ever you want .. "self.xx"
Timer every 1 second
Change attribute self.xx to mod((self.xx+1),2)
( we created a switch that changes its number to 1 and 0 every 1 second)
If self.xx = 1
Move down random y speed
Otherwise
Move up random y speed
This is in danger of moving off the screen.
1 loop per frame = 1/60th second.
You are asking the actor to move up to 264 pixels at a speed as low as 100 pixels per second . . . . (which would take 2.64 seconds) . . . in just 1/60th of a second !
He can put an actor to collide with
How much loops per frame must I take ?
Then you'd similarly be in danger of having an actor stuck bouncing against the barrier actor as it tries to move to a position beyond that actor.
Thanks but it doesn't work, can I send you my project to your e-mail so you see my problem ?
I don't understand the question, can you be more specific ?
You said that 1 max loop/ frame is not good, how much loops/frame must I take then?
I've not said that.
Adding 'then' on the end doesn't make the question any clearer
Can you be more specific, not about why you are asking the question, but about what the question means, how many loops per frame must you take to do what ?
This should work I think
depending on your screen size height , create an integer attribute self.xx
Rule1
if ANY of the conditions are valid
if self.position.Y is <= 300
if self.position.Y is >= 10
change attribute self.xx to mod((self.xx+1),2)
Rule2
if self.xx = 0
move down random speed
otherwise
move up random speed
The actor could reach Y300, xx is then randomly changed to 1, which will see the actor move up and off the screen.
@Socks it doesn't happen randomly it changes to either 1 or 0 ..
change attribute self.xx to mod((self.xx+1),2)
it will never move off screen
I see, yes xx is not random but toggling between 0 and 1, but the actor will still move off the screen, what would stop it ?
(and you are not allowed to answer 'he can put an actor to collide with).
@Socks
if ANY of the conditions are valid
if self.position.Y is <= 300
if self.position.Y is >= 10
change attribute self.xx to mod((self.xx+1),2)
so it will always stop when it goes (greater or = 300) or go (less than or = 10) that would stop it and toggle 1 or 0
I see, your rules say the opposite, they say smaller or equal to 300 . . . and greater or equal to 10 . . which would send the actor off the screen.
OH ! I didn't notice sorry my bad I meant the opposite
if self.position y is >=300
if self.position y is <= 10
It's too late now, you are off my Christmas card list.
By the way I prefer 1-x instead of mod((x+1),2), it's does the same thing, but simpler.
I bet you knew what i meant since the beginning , I didn't know this method 1-x .. i thought (mod and not(boolean)) where the only 2 ways to create a switch.. thanks for the info
I bet you knew your code was wrong all along, but were too ashamed to admit it, you felt owning up would bring shame on yourself and your family, and you would be forced to leave society and live in the woods in a tiny house made from old shoes. Eventually you would befriend some woodland creatures, you would teach them the ways of man, our language and our customs, then you would train them in the tactics of modern warfare and to fight like warriors . . . and in time you and your woodland creature army would mount an attack on society, destroying everything and everyone that rejected you, and once you'd established yourself as the supreme leader you (and your squirrel friends) would register on the forum using human identities and mark my posts in this thread as spam.
My code was right ! I just did a small typing mistake which you knew all along ! you just dragged it to make me feel ashamed .. I hope you get flagged though that would make me and my squirrel friends happy