Page 1 of 1
creating game - moving enemy
Posted: Fri Dec 13, 2013 9:44 pm
by star0629
I am wanting the enemy to appear at random times. At the moment it is a bird continuously moving across the card. I am wanting it to wait for atleast 20 seconds before appearing again and moving across the card. I am some ideas how to code this but am not entirely sure how exactly
thanks
Re: creating game - moving enemy
Posted: Fri Dec 13, 2013 9:49 pm
by dunbarx
Hi.
Do you already have a handler running, perhaps using the "move" command? Look up the "send" command, and look carefully at its "in time" variant.
Craig Newman
Re: creating game - moving enemy
Posted: Fri Dec 13, 2013 11:26 pm
by star0629
this is what i have so far when the game is running
on moveEnemy
set the left of button "box" to the left of button "box" + 5
if the left of button "box" > the right of card id"1003" then
set the left of button "box" to the left of card id"1003"
end if
end moveEnemy
the box being the enemy
Re: creating game - moving enemy
Posted: Sat Dec 14, 2013 1:37 am
by Simon
I am wanting it to wait for atleast 20 second...
liveCode uses many English words. hint hint
Simon
Edit: But if you can use "send" that is way cooler.
Re: creating game - moving enemy
Posted: Sat Dec 14, 2013 4:48 pm
by dunbarx
Hi.
Do you use invoke "sendEnemy" in a loop"? Anyway, when do you want "box" to disappear? When it hits the right of the card?
Try this experiment. In a button somewhere:
Code: Select all
on mouseUp
resetbox
end mouseUp
on resetbox
if the optionKey is down then
show btn "box"
exit to top
end if
set the visible of btn "box" to not the visible of btn "box"
set the loc of btn "box" to random(250),random(250)
send "resetbox" to me in 1 second
end resetbox
Hold down the optionKey to escape. Simon has hinted at a method using the "wait" command. Do look this up and consider it. But note that "wait" is blocking, and this may or may not be to your liking, depending on how you want this procedure to run.
Craig
Re: creating game - moving enemy
Posted: Sun Dec 15, 2013 11:25 pm
by capellan
Hi Star0629,
Check if this stack and it´s script could be useful
as inspiration or a starting point in your project:
http://andregarzia.on-rev.com/alejandro ... gman_2.zip
Have a nice week!
Al
Re: creating game - moving enemy
Posted: Mon Dec 16, 2013 3:12 am
by Newbie4
You could simply add a timer. When the box goes off the end of the screen, store the time (the seconds) into a global. Then do not move the box again until 20 seconds have passed.
Code: Select all
on moveEnemy
global gTime
if the seconds-gTime > 20 then
show button “box”
set the left of button "box" to the left of button "box" + 5
if the left of button "box" > the right of card id"1003" then
set the left of button "box" to the left of card id"1003"
hide button “box”
put the seconds into gTime
end if
end moveEnemy
When the program starts up, you may have to initialize the global so that it works right away.
This is a simple approach, you may think of another way.
Re: creating game - moving enemy
Posted: Mon Dec 16, 2013 12:45 pm
by chris25
I have a question for you capellan, or if someone else might be good enough to answer I would appreciate it. It concerns just one line of script in your card in the Keydown message namely:
if tKey is in "1,2,3,4,5,6,7,8,9,q,w,e,a,s,d,z,x,c" and the tEnabled of this card <> false
In the above your temporary variable is declared only once within the keydown, what puzzles me is this: if it is false assumes the possibility of it being 'true'. How can it possibly ever be true when it has no declaration or value assigned to it. It appears in this one line and that is it, where is its property/value/meaning acquired from? It's what confuses me sometimes when I see these.
and in your image mlr2:
move me to the points of grc 1 in the MovingTime of this stack seconds
The same applies here with 'movingTime' except that I do not even know what this is, it is not a command or a function because it is no where else declared throughout the whole program. So again it seems a tVariable?
I am still very knew to all this and still trying to grapple with a the basics.
Thankyou
chris
Re: creating game - moving enemy
Posted: Mon Dec 16, 2013 12:53 pm
by Klaus
chris25 wrote:...
if tKey is in "1,2,3,4,5,6,7,8,9,q,w,e,a,s,d,z,x,c" and the tEnabled of this card <> false
...
tEnabled is
NOT a variable ->
THE tEnabled of cd ...
It is a
custom property of a card, which obviously might have been set earlier.
Re: creating game - moving enemy
Posted: Mon Dec 16, 2013 1:34 pm
by chris25
Oh, thankyou. And the movingtime? looked also like a custom property because of your emboldened definite article, but not so, nothing in the stack property and nothing in the image property inspector either.
Re: creating game - moving enemy
Posted: Mon Dec 16, 2013 1:43 pm
by Klaus
"movingtime"?
Sorry, did not load/examine the stack Alejandro posted,
just commented the the line you have posted.
Re: creating game - moving enemy
Posted: Mon Dec 16, 2013 8:15 pm
by star0629
Newbie4 wrote:You could simply add a timer. When the box goes off the end of the screen, store the time (the seconds) into a global. Then do not move the box again until 20 seconds have passed.
Code: Select all
on moveEnemy
global gTime
if the seconds-gTime > 20 then
show button “box”
set the left of button "box" to the left of button "box" + 5
if the left of button "box" > the right of card id"1003" then
set the left of button "box" to the left of card id"1003"
hide button “box”
put the seconds into gTime
end if
end moveEnemy
When the program starts up, you may have to initialize the global so that it works right away.
This is a simple approach, you may think of another way.
thank you soo mcuh this is exactly what i needed, it works perfectly! and doesnt stop running the entire program also not complicated to understand either

thanks!!