Trying to explode a submarine using a sprite
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Trying to explode a submarine using a sprite
Local tSubExplode has been declared on this card: If I put 0 into this local variable, upon collision the mine just passes the sub.
on preOpenStack
put 0 into tSubExplode
end preOpenStack
If I then add a 1 to the above, then upon collision the sub just disappears. I am trying to make the sub (in a button) go through a routine of 5 sequential .png's already on that card and hidden.
on subExplosion
--Loop through the sub explosion images, once the last one has been reached.
if tSubExplode is 0 then
--Set the new sequentially numbered subExplosion image.
set the icon of button "BlackSub" to "ExplodingSub_" & tSubExplode & "_.png"
end if
end Subexplosion
on collisions
if intersect (btn "blackSub" , img "mine1") then
subExplosion
--set the icon of button "BlackSub" to "exStage1.png" (works fine)
--answer "stop game"
--exit to top
end if
end collisions
Would be nice to have some little guidance here - thankyou
kind regards
chris
on preOpenStack
put 0 into tSubExplode
end preOpenStack
If I then add a 1 to the above, then upon collision the sub just disappears. I am trying to make the sub (in a button) go through a routine of 5 sequential .png's already on that card and hidden.
on subExplosion
--Loop through the sub explosion images, once the last one has been reached.
if tSubExplode is 0 then
--Set the new sequentially numbered subExplosion image.
set the icon of button "BlackSub" to "ExplodingSub_" & tSubExplode & "_.png"
end if
end Subexplosion
on collisions
if intersect (btn "blackSub" , img "mine1") then
subExplosion
--set the icon of button "BlackSub" to "exStage1.png" (works fine)
--answer "stop game"
--exit to top
end if
end collisions
Would be nice to have some little guidance here - thankyou
kind regards
chris
Re: Trying to explode a submarine using a sprite
The key problem seems to be:
If the variable tSubExplode = 0 then it will show icon "ExplodingSub_0_.png". If it is any other value then it will not reset the icon. Perhaps you mean "> 0"?
Code: Select all
if tSubExplode is 0 then
set the icon of button "BlackSub" to "ExplodingSub_" & tSubExplode & "_.png"
end if
Re: Trying to explode a submarine using a sprite
Hi friends,
ALWAYS use parens when concatenating object names:
...
set the icon of button "BlackSub" to ("ExplodingSub_" & tSubExplode & "_.png")
...
But to be honest, I don't get your problem at all
When do you want to show your animation?
Waht condition needs to be met?
Best
Klaus
ALWAYS use parens when concatenating object names:
...
set the icon of button "BlackSub" to ("ExplodingSub_" & tSubExplode & "_.png")
...
But to be honest, I don't get your problem at all

When do you want to show your animation?
Waht condition needs to be met?
Best
Klaus
Re: Trying to explode a submarine using a sprite
Hallo, I have been working through the variable with breakpoints, and watching how even when I set it to 1 it adds 1 and still does nothing nothing at all. Just a disappearing sub all the time.
Yes Klaus I have read fourthworlds strategy and consistency for livecode scripting. I am trying to conform, as best as I can.
I want to show the animated effect on intersect, (mine hits sub), I have 5 images each one showing a submarine blowing up (png's that I made in photoshop).
When mine hits sub, the 5 image sequence replaces the submarine image (that is contained in a button). All then cease to exist.
I can easily set a btn icon to an image, I can make a gif animation appear (but the latter is not good for the LC game engine - understandably), But then I thought that by using scripting to achieve this effect my very simple easy game (that is now complexed itself by my urge for creativity even with self imposed strict limits) using LC to do the job has to be more advantageous for speed and fluency, and it gives me more skills.
Hope this explains it.
since asking the question the my new code in the custom handler is now:
But still not getting anywhere

Yes Klaus I have read fourthworlds strategy and consistency for livecode scripting. I am trying to conform, as best as I can.
I want to show the animated effect on intersect, (mine hits sub), I have 5 images each one showing a submarine blowing up (png's that I made in photoshop).
When mine hits sub, the 5 image sequence replaces the submarine image (that is contained in a button). All then cease to exist.
I can easily set a btn icon to an image, I can make a gif animation appear (but the latter is not good for the LC game engine - understandably), But then I thought that by using scripting to achieve this effect my very simple easy game (that is now complexed itself by my urge for creativity even with self imposed strict limits) using LC to do the job has to be more advantageous for speed and fluency, and it gives me more skills.
Hope this explains it.
since asking the question the my new code in the custom handler is now:
Code: Select all
on subExplosion
--Loop through the sub explosion images, once the last one has been reached.
if tSubExplode is 2 then
put 1 into tSubExplode
else
add 1 to tSubExplode
end if
--Set the new sequentially numbered subExplosion image.
set the icon of button "BlackSub" to ("ExplodingSub_" & tSubExplode & "_.png") -- please note addition of parenthesis :D
end Subexplosion
Re: Trying to explode a submarine using a sprite
Loop = repeat, not?
Is that what you are looking for:
?
Is that what you are looking for:
Code: Select all
...
repeat with i = 1 to 5
set the icon of button "BlackSub" to ("ExplodingSub_" & i & "_.png")
wait 100 millisecs with messages
end repeat
...
Re: Trying to explode a submarine using a sprite
Ok logically yes this should have been better actually. But still, the sub just disappears. Every time I check the button properties inspector, and it consistently re-sets the id 1009 (icon ID of sub image), it sets this every time to a 0. I really do not know why it would keep doing this. This would explain WHY the sub disappears, the icon id is being removed. But NOT being replaced with the .png ID's
regards
chris
regards
chris
Re: Trying to explode a submarine using a sprite
Hi Chris,
I never used image NAMES as an icon, so maybe you should try this with the actual image IDs?
Just a guess...
Best
Klaus
I never used image NAMES as an icon, so maybe you should try this with the actual image IDs?
Just a guess...
Best
Klaus
Re: Trying to explode a submarine using a sprite
I can not use ID numbers because there are five images. This would mean that the code here: set the icon of button "BlackSub" to ("ExplodingSub_" & i & "_.png") the 'ExplodingSub' would have to contain 5 ID numbers. Instead each of the images is named exactly the same but with the number 1 number 2 etc after the name. How can I use ID numbers in this?
Re: Trying to explode a submarine using a sprite
Try;
Code: Select all
set the icon of button "BlackSub" to the id of image ("ExplodingSub_" & i & "_.png")
LiveCode Development & Training : http://splash21.com
Re: Trying to explode a submarine using a sprite
Hi Chris,
Make sure your 5 images have subsequent IDs. Like in this EXAMPLE:
1004 -> ExplodingSub_1_.png
1005 -> ExplodingSub_2_.png
1006 -> ExplodingSub_3_.png
1007 -> ExplodingSub_4_.png
1008 -> ExplodingSub_5_.png
Now translate the IDs to image names:
...
## We use ADDITION (to the first ID) to "compute" the correct ID:
repeat with i = 0 to 4
set the icon of button "BlackSub" to (1104 + i)
end repeat
...
Best
Klaus
oh, come on! See below...chris25 wrote:I can not use ID numbers because there are five images.

Hm, then you might need to use another code!chris25 wrote:This would mean that the code here: set the icon of button "BlackSub" to ("ExplodingSub_" & i & "_.png") the 'ExplodingSub' would have to contain 5 ID numbers. Instead each of the images is named exactly the same but with the number 1 number 2 etc after the name.
Make sure your 5 images have subsequent IDs. Like in this EXAMPLE:
1004 -> ExplodingSub_1_.png
1005 -> ExplodingSub_2_.png
1006 -> ExplodingSub_3_.png
1007 -> ExplodingSub_4_.png
1008 -> ExplodingSub_5_.png
Now translate the IDs to image names:
...
## We use ADDITION (to the first ID) to "compute" the correct ID:
repeat with i = 0 to 4
set the icon of button "BlackSub" to (1104 + i)
end repeat
...
Check the ID of your image(s) and set the ICON of your button to that number.chris25 wrote:How can I use ID numbers in this?
Best
Klaus
Re: Trying to explode a submarine using a sprite
Pleased to say that I have it working, I got rid of underscores which I should not have used, I added a second if to the second line, and took Dhurtt's advice and used ID instead of names and of course used the variable name instead of 'i', though I know that you said this Klaus; and Klaus, I have just read your response. I meant that I could not used 5 ID's within this code as it stood. Klaus I will be trying out your suggestion as well, so much appreciated, as variety will help me learn, thankyou.
I need to put a delay in between each successive image change. I thought of a Variable called tSubInterval whereby the variable would contain timed delay and then include this inside a repeat statement. I will try it, but it also would be nice to have another suggestion. Only asking for hints.
Kind regards
chris
Code: Select all
on collisions
if intersect ( btn "BlackSub" , img "mine1" ) then
if gSubExplode is 5 then
put 1 into gSubExplode
else
add 1 to gSubExplode
end if
set the icon of btn "BlackSub" to the id of img ("exStage" & gSubexplode & ".png" )
--answer "oops"
--exit to top
end if
end collisions
Kind regards
chris
Re: Trying to explode a submarine using a sprite
If you like more "food for thought", check my answer here:
http://forums.runrev.com/phpBB2/viewtop ... 552#p90445

http://forums.runrev.com/phpBB2/viewtop ... 552#p90445

Re: Trying to explode a submarine using a sprite
Hi Klaus, I had no idea that you had replied to this it was so long ago. But I will have to take my time later on to go through this if you don't mind. I have a more pressing issue. Could you point me to any resources that talk about the different ways to prevent messages from being delivered within a handler. In other words, LC is running unseen routines in the background, for example, you hide an object and it is gone, but if that object is moving then valuable processing time is being used up and the object is still actually running in the background. Or you have 2 routines in one handler, the first one runs and is finnished and the second one starts, but the first one is still in effect taking up valuable processing time - I know that I am not using correct language to ask the question, but I am beginning to think a little deeper into processes and it is hard to know exactly what questions I should be asking.
kind regards
chris
kind regards
chris
Re: Trying to explode a submarine using a sprite
Hi Chris,
not sure what you mean? Could you create a script in "pseudo-code" that may give me a hint?
Best
Klaus
not sure what you mean? Could you create a script in "pseudo-code" that may give me a hint?
Best
Klaus
Re: Trying to explode a submarine using a sprite
I don't know, but I'm guessing the problem is something like a "hidden" submarine that has already "exploded" is still responding to cursor keypresses and moving an invisible (or visible ghost) submarine which shouldn't be there any more?
Probably you are using something along the lines of "send updateSubPositionOrSpeed to me in some milliseconds" within the handler "updateSubPositionOrSpeed". You could set a "flag" (a variable with an "on/off" state) and when you initialise the game you set the flag to true. Then in the updateSubPositionOrSpeed handler youWhen the sub explodes you set sFlag to false and so when the updateSubPositionOrSpeed handler happens next it does not send the next update and the ghost sub stops moving/responding. sFlag would be a script local variable that can be accessed by both the updateSubPositionOrSpeed and the explodeSubHere handlers.
At least it might be something along those lines. We'd need to see a bit more script to tell if this is appropriate to your situation, but I hope you get the idea here.
Probably you are using something along the lines of "send updateSubPositionOrSpeed to me in some milliseconds" within the handler "updateSubPositionOrSpeed". You could set a "flag" (a variable with an "on/off" state) and when you initialise the game you set the flag to true. Then in the updateSubPositionOrSpeed handler you
Code: Select all
if sFlag is true then
send updateSubPositionOrSpeed to me in 50 milliseconds
end if
At least it might be something along those lines. We'd need to see a bit more script to tell if this is appropriate to your situation, but I hope you get the idea here.