Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Hello, I'm having issues with the intersect command triggering when I use "move without waiting" on the object that is meant to be intersecting, additionally any IF statements after the movement do not seem to proc and I'm very unsure of why this is...
on spawnstart
set the filename of image "enemy1" to "./BetterSprites/Enemy.php.gif"
Set the bottom of image "enemy1" to the top of this card
send enemy1 to me in 3 seconds
end spawnstart
on enemy1
Set the bottom of image "Enemy1" to the top of this card
put item 1 of the loc of image "enemy1" into tX
put item 2 of the loc of image "enemy1" into tY
put random(400) into tX
set the loc of image "enemy1" to tX,tY
if the left of image "enemy1" < the left of this card then
set the left of image "enemy1" to the left of this card
end if
if the right of image "enemy1" > the right of this card then
set the right of image "enemy1" to the right of this card
end if
put item 1 of the loc of image "enemy1" into tX
set the loc of image "enemy1" to tX,tY
put "false" into intersect1
move image "enemy1" to tX,520 without waiting ---------------------------------< Erroneous line? Perhaps move does not allow IFs to proc?
---------------------------------------------------------------------------------------------------Up to this point works fine, i assume it's an error with the previous line(???)
if the top of image "enemy1" > the bottom of this card then
loselife
spawnstart
end if
If intersect(image "enemy1", image "Laser1") then
scoregain
spawnstart
set the top of image "Laser1" to the bottom of this card
set the right of image "Laser1" to the left of this card
end if
If intersect(image "enemy1", image "Laser2") then
scoregain
spawnstart
set the top of image "Laser2" to the bottom of this card
set the right of image "Laser2" to the left of this card
end if
if intersect(image "enemy1", image "player") then
loselife
spawnstart
end if
end enemy1
I've tried to switch out the "move without waiting" syntax in favor of "move relative" in a conditional loop, but that creates even more issues and the intersects still do not always trigger... Any help would be deeply appreciated, and I'm pretty stumped about what is going wrong
Your script runs OK, but there is no reason for the intersect to trigger, because the handler ends way before any of your intersect tests have a chance to work. Put this just before the "end enemy1" handler:
As, so it isn't a semantic error as I thought? Just a timing one?
That explains why the repeat was working earlier, perhaps I could put the IF statements in a conditonal loop or something so they continually execute? Or would that cause problems...?
Thanks anyway, Your reply was very helpful
edit: tried a repeat, it failed
I suppose I could just end the handler with a "send to me" and contain the IF statements there...
edit2: Failing the above it is now stuck in an infinite loop...is there a command like "Command ." on mac for windows that I can use to abort the loop?
The "move" command blocks, the rest of the handler will not execute while it happens. You can add "with messages" but even so, the current handler will not continue; only other user actions will trigger.
So the move command is not appropriate here. Instead you need to move the object to the mouseloc using a "send <msg> in <time>" construct.
There are many examples of this in the forums, but if you need help then ask.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
jacque wrote:The "move" command blocks, the rest of the handler will not execute while it happens. You can add "with messages" but even so, the current handler will not continue; only other user actions will trigger.
So the move command is not appropriate here. Instead you need to move the object to the mouseloc using a "send <msg> in <time>" construct.
There are many examples of this in the forums, but if you need help then ask.
I'm not sure I follow, the "send" command as "send to me in x seconds"? Or another syntax? Your answer answered my queries as to why it was not working, but i'm still fairly unfamiliar with the syntax variations and I'm not entirely sure what you mean, sorry.
--Up to this point works fine, i assume it's an error with the previous line(???)
breakpoint
if the top of image "enemy1" > the bottom of this card then
loselife
spawnstart
end if
Now how often is that breakpoint triggered?
I can see that you are thinking there is a "polling" taking place where it checks your intersect but there is none. That code does not loop... 1 time only.
Now I'm not saying you should put a loop in there as they are not good for this sort of thing. But as suggested can you figure out how to use send in time?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
--Up to this point works fine, i assume it's an error with the previous line(???)
breakpoint
if the top of image "enemy1" > the bottom of this card then
loselife
spawnstart
end if
Now how often is that breakpoint triggered?
I can see that you are thinking there is a "polling" taking place where it checks your intersect but there is none. That code does not loop... 1 time only.
Now I'm not saying you should put a loop in there as they are not good for this sort of thing. But as suggested can you figure out how to use send in time?
Simon
See, that's an issue that I couldn't get around...
The intersects happens at various times throughout the movement so i can't use send in a way that works 100% of the time, there's too much variation in intersect times, and the intersecting item is also moving so I can't allocate the intersect to that either ...
Make three buttons. Name one of them "movingButton" and place it on the left side of the card. Make another, named "targetButton", and place it on the right side of the card, but at the same Y location as the first (on the same horizontal."line"). Now make another button and place this in its script:
on mouseUp
put "movingButton" into tButton
moveThatThing tButton
end mouseUp
on moveThatThing var
set the left of btn var to the left of btn var + 1
if intersect(btn var, btn "targetButton") then
answer "HIT!"
exit to top
end if
send "moveThatThing var" to me in 1
end moveThatThing
The nice thing about using the "send" command this way is that, as Jacque pointed out, it is not blocking. You have control over everything while the button is moving. There is a lot of stuff you need to do to this sort of script to make your project work the way you want it to, but this is just an example of how to create a "loop", without using "repeat", to move an object without using "move", and to get out of it all when the intersect actually happens, not at some undetermined time.
Make three buttons. Name one of them "movingButton" and place it on the left side of the card. Make another, named "targetButton", and place it on the right side of the card, but at the same Y location as the first (on the same horizontal."line"). Now make another button and place this in its script:
on mouseUp
put "movingButton" into tButton
moveThatThing tButton
end mouseUp
on moveThatThing var
set the left of btn var to the left of btn var + 1
if intersect(btn var, btn "targetButton") then
answer "HIT!"
exit to top
end if
send "moveThatThing var" to me in 1
end moveThatThing
The nice thing about using the "send" command this way is that, as Jacque pointed out, it is not blocking. You have control over everything while the button is moving. There is a lot of stuff you need to do to this sort of script to make your project work the way you want it to, but this is just an example of how to create a "loop", without using "repeat", to move an object without using "move", and to get out of it all when the intersect actually happens, not at some undetermined time.
on checkforcollisions
if the top of image "enemy1" > the bottom of this card then
loselife
spawnstart
end if
If intersect( image "enemy1" , image "Laser1" ) then
scoregain
spawnstart
set the top of image "Laser1" to the bottom of this card
set the right of image "Laser1" to the left of this card
end if
If intersect( image "enemy1" , image "Laser2" ) then
scoregain
spawnstart
set the top of image "Laser2" to the bottom of this card
set the right of image "Laser2" to the left of this card
end if
if intersect( image "enemy1" , image "player" ) then
loselife
spawnstart
end if
send checkforcollisions to me in 1 millisecond
end checkforcollisions
How do the objects move? If you step through the handler, what happens when you see the objects intersect visually?
Craig
The intersects now work, I called the synthetic loop -before- the movement to be certain it would carry through and it is now working...However the program freezes on card transition and references there being "no such object as (object from last card)"...I tried to use a variable to make sure no modules are triggering post-transition, but it seemingly makes no difference.
on enemy1
if gamecard is "true" then
Set the bottom of image "Enemy1" to the top of this card
put item 1 of the loc of image "enemy1" into tX
put item 2 of the loc of image "enemy1" into tY
put random(400) into tX
set the loc of image "enemy1" to tX,tY
if the left of image "enemy1" < the left of this card then
set the left of image "enemy1" to the left of this card
end if
if the right of image "enemy1" > the right of this card then
set the right of image "enemy1" to the right of this card
end if
put item 1 of the loc of image "enemy1" into tX
set the loc of image "enemy1" to tX,tY
put "false" into intersect1
send checkforcollisions to me
move image "enemy1" to tX,520 in 5 seconds
end if
end enemy1
on checkforcollisions
if gamecard is "true" then
if the top of image "enemy1" > the bottom of this card then
loselife
if gamecard is "true" then
enemy1
end if
end if
If intersect(image "enemy1" , image "Laser1" , "opaque pixels") then
put "false" into var_bool_fired
scoregain
if gamecard is "true" then
enemy1
end if
set the top of image "Laser1" to the bottom of this card
set the right of image "Laser1" to the left of this card
end if
If intersect( image "enemy1" , image "Laser2" , "opaque pixels") then
put "false" into var_bool_fired
scoregain
if gamecard is "true" then
enemy1
end if
set the top of image "Laser2" to the bottom of this card
set the right of image "Laser2" to the left of this card
end if
if intersect(image "enemy1" , image "player" , "opaque pixels") then
loselife
if gamecard is "true" then
enemy1
end if
end if
send checkforcollisions to me in 0.01 seconds
end if
end checkforcollisions
The variable that I thought would deactivate the loop/movements:
on loselife
add "-1" to var_lives
if var_lives is 2 then
set the filename of image "lives" to "./Bettersprites/text/twolives.png"
end if
if var_lives is 1 then
set the filename of image "lives" to "./Bettersprites/text/onelife.png"
end if
if var_lives is 0 then
put "false" into gamecard
go to card 3
end if
end loselife
I assume that the synthetic loop is the issue as removing it seems to solve the freezes...but of course i need it for the intersects...
When you navigate to another card, you have to be careful that references to objects on other cards are called with explicit pathnames. It may seem excessive to constantly say "image soAndSo of card someCard", and this is true if you stay on a single card, since the current card is always assumed by LC unless it is told differently.
But you should be able to find the error in your code. And then just rewrite all object references that are causing problems to explicit ones.