damage from enemy and destroying object
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
damage from enemy and destroying object
So I've been working on a Tower Defense game for class, and I am finally starting to move a long a little better with it, but I have come across a few more questions.
1. local and global variables. Is a global variable global between all cards in a stack? or just all elements of one card? I need a life variable that is reset on each individual card. I figured the easiest way is to make 1 card, and then copy it for each level, then make some slight tweaks. But I need to know how to make sure the variable for health is not carried over from card to card.
2. I have the enemies moving along a set path. If they make it to the end, the player takes damage. I need to either turn the enemies invisible or destroy them when they reach the last point of the path. I was attempting to use the "on motionEnd" message, but it doesn't seem to be working.
3. I am having trouble getting the life counter to go down. I am not very familiar with LiveCode yet, so I am used to just putting playerLife -= 1, or playerLife = playerLife -1, but neither of these seems to work, in fact I get errors with these. I have also tried subtract 1 from playerLife. I have not been able to test this one yet since I am waiting to figure out the variable situation, but if anyone can tell me if this is a good way to subtract 1 from a variable when a requirement is met, that would be great.
As always, thanks for the help!
1. local and global variables. Is a global variable global between all cards in a stack? or just all elements of one card? I need a life variable that is reset on each individual card. I figured the easiest way is to make 1 card, and then copy it for each level, then make some slight tweaks. But I need to know how to make sure the variable for health is not carried over from card to card.
2. I have the enemies moving along a set path. If they make it to the end, the player takes damage. I need to either turn the enemies invisible or destroy them when they reach the last point of the path. I was attempting to use the "on motionEnd" message, but it doesn't seem to be working.
3. I am having trouble getting the life counter to go down. I am not very familiar with LiveCode yet, so I am used to just putting playerLife -= 1, or playerLife = playerLife -1, but neither of these seems to work, in fact I get errors with these. I have also tried subtract 1 from playerLife. I have not been able to test this one yet since I am waiting to figure out the variable situation, but if anyone can tell me if this is a good way to subtract 1 from a variable when a requirement is met, that would be great.
As always, thanks for the help!
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Re: damage from enemy and destroying object
Hi Ethan,
For Q1, global variables, usually named with a lower case g in the front, once populated exist until the program ends or until you empty them. They extend across and are available to cards and to all objects on open stacks. You will probably want to use local variables. These only exist until the handler that started them finishes. You can also set up whats called a local script variable. Usually named with a lower case s in the front. These are declared at the top of the card script above and outside of any handlers. This makes them available to all the handlers in the card script.
For Q2, look up motionStopped in the dictionary. I hit the easy button on this one.
For Q3, well... lets get past 1 and 2 first.
For Q1, global variables, usually named with a lower case g in the front, once populated exist until the program ends or until you empty them. They extend across and are available to cards and to all objects on open stacks. You will probably want to use local variables. These only exist until the handler that started them finishes. You can also set up whats called a local script variable. Usually named with a lower case s in the front. These are declared at the top of the card script above and outside of any handlers. This makes them available to all the handlers in the card script.
For Q2, look up motionStopped in the dictionary. I hit the easy button on this one.

For Q3, well... lets get past 1 and 2 first.
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
Re: damage from enemy and destroying object
Hi.
What quailcreek means is that you need to dig into the lessons and tutorials alongside of your coding effort. I think that jumping right into a project is just fine, but it will be very frustrating unless you concurrently are playing with the examples and other resources. And I also recommend making simpler stacks, of any kind at all, as drills.
Q3: The short answer to your third question is a common one among those who are familiar with other languages. To subtract 1 from a variable, the xTalk way does this
instead of
Seem overly wordy in comparison?? You may think so with a simple line like that, but I can promise you that as you become even a fairly proficient beginner, you will see that you save astonishing amounts of code, never mind variable typing and other management tasks. You will see. The difference in style, and that is all it is, derives from the change in paradigm. Trust me.
And ask here all day. There is limitless help available.
Craig Newman
What quailcreek means is that you need to dig into the lessons and tutorials alongside of your coding effort. I think that jumping right into a project is just fine, but it will be very frustrating unless you concurrently are playing with the examples and other resources. And I also recommend making simpler stacks, of any kind at all, as drills.
Q3: The short answer to your third question is a common one among those who are familiar with other languages. To subtract 1 from a variable, the xTalk way does this
Code: Select all
put x - 1 into x
Code: Select all
x = x-1
And ask here all day. There is limitless help available.
Craig Newman
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: damage from enemy and destroying object
Ok, so I got all of these issues figured out. I think the last step I have before moving onto player controls is setting up the spawning of enemies. I need to have 10 waves, each with increasing difficulty. I'm not sure how to do this though. How can I have multiple copies of an object at once and have them spawn at different times and intervals?
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Re: damage from enemy and destroying object
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
Re: damage from enemy and destroying object
Quailcreek has suggested a good example. After you play with Ben's stack for a while, check out the "create" and "clone" commands in the dictionary. You may want to start leaning about "groups" as well, if these enemies are intended to march en defilade toward your hero.
Craig
Craig
Re: damage from enemy and destroying object
This is correct syntax too. Since you can also use "put x-1 into x" as mentioned, pick whichever form you like better.I have also tried subtract 1 from playerLife. I have not been able to test this one yet
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: damage from enemy and destroying object
quailcreek wrote:Take a look at this stack, Ethan.
http://revonline2.runrev.com/stack/675/SheepHerder
This helps a little bit but still leaves most of the problems unanswered. I still don't know how to make 10 separate waves, and I don't know how to make the enemies come in random intervals.
I'm thinking maybe make 2 loops, 1 loop will go to 10, and will display a label showing which wave is starting, inside this loop, I can create another loop that also counts to 10, and use 'random' to make the spawning of enemies random. Is there a way to incorporate 'random' so that all 10 have to be deployed over a certain course of time? For example, say I want all 10 enemies deployed within 2 minutes, but I want them deployed at completely random times within those 2 minutes. Any ideas on that?
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: damage from enemy and destroying object
also, I'm used to working with prefabs in game engines, where I can easily instantiate them. How do I do this with LiveCode? do I just leave everything on the card and turn them invisible?
Re: damage from enemy and destroying object
Hi.
I neither play nor make games of any kind.
Know up front that LC is far more a general purpose programming environment than a game making one. So the toolbox, or "library" of prefabs (and I only can surmise what those are) and other pre-made game-like objects (sprites?) simply do not exist.
Colin? Are you reading this? Is even my terminology correct?
You can, in LC, "instantiate" objects in a few ways. You can pre-load them and then show them wherever you need to. Or you can clone them from a master. Or you can create them from whole cloth. I assume this is similar to any other environment.
As for moving them as required, that is easily managed. But you have to choreograph under script control; that means under your own direct programming. There are no prefab methods that you can draw upon, no library of motion routines you can apply to existing objects.
But my point is this: are you frustrated that these specialized tools seem not to exist? Or is it that you still do not have the skills to implement your vision? Lets talk about this for just a little while. Oh, and did I mention I am likely not the best person to moderate this?
Craig
I neither play nor make games of any kind.
Know up front that LC is far more a general purpose programming environment than a game making one. So the toolbox, or "library" of prefabs (and I only can surmise what those are) and other pre-made game-like objects (sprites?) simply do not exist.
Colin? Are you reading this? Is even my terminology correct?
You can, in LC, "instantiate" objects in a few ways. You can pre-load them and then show them wherever you need to. Or you can clone them from a master. Or you can create them from whole cloth. I assume this is similar to any other environment.
As for moving them as required, that is easily managed. But you have to choreograph under script control; that means under your own direct programming. There are no prefab methods that you can draw upon, no library of motion routines you can apply to existing objects.
But my point is this: are you frustrated that these specialized tools seem not to exist? Or is it that you still do not have the skills to implement your vision? Lets talk about this for just a little while. Oh, and did I mention I am likely not the best person to moderate this?
Craig
Re: damage from enemy and destroying object
Hi ethan,
Tower Defense...
You really should not expect anyone here to know or want to know what that game is. Pretty much no one cares... we do care about answering direct questions.
Sorry about that.
So for other liveCoders;
Tower Defense is a game that;
Has a snaking path that leads to the tower that the bad guys move along to get to the tower to destroy it.
Your job is to place gun emplacements along the path that auto fire on baddies moving up the path. You drag and drop the gun emplacements improving your results on each run.
Gun emplacements have varying effectiveness, arrows/guns/missiles and limited distance.
Bad guys take varying degrees of damage to destroy. Several run the path at one time.
Once the round has started it plays out till enemy's are destroyed or the tower is invaded.
Ethan, start with that next time... and tell your classmates.
Now all of this is possible in liveCode, one part that I think will be tough. The gun emplacements rotate and track the closest enemy. Once out of range they stop firing.
Simon
Tower Defense...
You really should not expect anyone here to know or want to know what that game is. Pretty much no one cares... we do care about answering direct questions.
Sorry about that.
So for other liveCoders;
Tower Defense is a game that;
Has a snaking path that leads to the tower that the bad guys move along to get to the tower to destroy it.
Your job is to place gun emplacements along the path that auto fire on baddies moving up the path. You drag and drop the gun emplacements improving your results on each run.
Gun emplacements have varying effectiveness, arrows/guns/missiles and limited distance.
Bad guys take varying degrees of damage to destroy. Several run the path at one time.
Once the round has started it plays out till enemy's are destroyed or the tower is invaded.
Ethan, start with that next time... and tell your classmates.
Now all of this is possible in liveCode, one part that I think will be tough. The gun emplacements rotate and track the closest enemy. Once out of range they stop firing.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: damage from enemy and destroying object
Some ideas: You don't want to use repeat loops because each one will block all other actions until it completes. Instead, use the "send <command> in <time> structure (see the "send" command in the dictionary.)
Randomization would happen by sending each command at a random number of seconds. By using "send" you can run more than one simultaneous loop while still allowing the user to move and click the mouse.
I agree the rotating guns will be tricky. Doable probably, but challenging.
Randomization would happen by sending each command at a random number of seconds. By using "send" you can run more than one simultaneous loop while still allowing the user to move and click the mouse.
I agree the rotating guns will be tricky. Doable probably, but challenging.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: damage from enemy and destroying object
I completely agree with you guys that this is not the program to use for making this game, however it is an assignment for a class, and the choices of games were limited. Thank you for some of the answers. I will continue to look into these. I have run into a bit of a snag. While experimenting with some bits of code, I seem to have done something that immediately freezes the program when it gets to the card with the problem code. The problem is that I must have accidently saved it after this code was activated, because now every time I open that program, it freezes. Is there any hope to somehow get back to the source code so I can delete that code? Or am I doomed to start over from scratch...
Re: damage from enemy and destroying object
I don't think anyone said that!...that this is not the program to use for making this game
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Posts: 46
- Joined: Sun Feb 14, 2016 9:08 am
Re: damage from enemy and destroying object
it seems to be Craig's opinion. And I don't think that LC is necessarily made for creating games. It seems like it could be put to much better use doing other things.