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!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
Sekoshiba
- Posts: 31
- Joined: Thu Sep 26, 2013 8:23 pm
Post
by Sekoshiba » Fri Dec 13, 2013 12:10 am
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...
My code at the moment is looking like this.
Code: Select all
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

-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10332
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Fri Dec 13, 2013 12:46 am
Hi.
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:
Code: Select all
end if
answer "End of Handler"
end enemy1
You need to rework this so that your tests are made while the move is being made. Do you need help with this?
Craig Newman
-
Sekoshiba
- Posts: 31
- Joined: Thu Sep 26, 2013 8:23 pm
Post
by Sekoshiba » Sat Dec 14, 2013 2:22 pm
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?
-
Sekoshiba
- Posts: 31
- Joined: Thu Sep 26, 2013 8:23 pm
Post
by Sekoshiba » Sun Dec 15, 2013 11:02 am
Manually backdated because of the loop, i'm completely stumped as to how to go about having the IF statements execute during the move...
Edit/bump: Halp D:
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Sun Dec 15, 2013 9:20 pm
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
-
Sekoshiba
- Posts: 31
- Joined: Thu Sep 26, 2013 8:23 pm
Post
by Sekoshiba » Sun Dec 15, 2013 10:53 pm
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.
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Sun Dec 15, 2013 11:15 pm
Hi Sekoshiba,
Try this, set a breakpoint like shown below
Code: Select all
--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!
-
Sekoshiba
- Posts: 31
- Joined: Thu Sep 26, 2013 8:23 pm
Post
by Sekoshiba » Sun Dec 15, 2013 11:18 pm
Simon wrote:Hi Sekoshiba,
Try this, set a breakpoint like shown below
Code: Select all
--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

...
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Sun Dec 15, 2013 11:24 pm
Lot of "can't" in there.
Here this will help put you out of your misery:
https://sites.google.com/a/pgcps.org/livecode/home
Go to Example Games lots of kids using send with intersect.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10332
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Sun Dec 15, 2013 11:25 pm
Hi.
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:
Code: Select all
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.
Craig Newman
-
Sekoshiba
- Posts: 31
- Joined: Thu Sep 26, 2013 8:23 pm
Post
by Sekoshiba » Sun Dec 15, 2013 11:43 pm
dunbarx wrote:Hi.
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:
Code: Select all
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.
Craig Newman
aaaah, I see what you mean
I shall try this!
-
Sekoshiba
- Posts: 31
- Joined: Thu Sep 26, 2013 8:23 pm
Post
by Sekoshiba » Mon Dec 16, 2013 2:21 pm
Having tried the "send in x" suggestions, it worked
The intersects however...still do not :c
The module I used as a synthetic repeat is as follows...
Code: Select all
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
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10332
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Mon Dec 16, 2013 4:49 pm
Hi.
How do the objects move? If you step through the handler, what happens when you see the objects intersect visually?
Craig
-
Sekoshiba
- Posts: 31
- Joined: Thu Sep 26, 2013 8:23 pm
Post
by Sekoshiba » Mon Dec 16, 2013 7:07 pm
dunbarx wrote:Hi.
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.
The spawn/intersect script:
Code: Select all
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:
Code: Select all
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...
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10332
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Mon Dec 16, 2013 8:07 pm
Hi.
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.
Craig