Questions About String Lists & Combat

182crazyking
01 Dec 2012, 19:38
Hey guys, I've got a pair of newbie questions about some stuff that I'm working on, and I'd really appreciate it if you could help answer them for me! :)

First off, I want to add a value to a list upon using an object, and then refer to that list later on (learning a move for combat, then using it in actual combat). So I added this script:



(I made my test game Tron-esque, for laughs.)
Now, later in the game I run a script telling the game to display a menu with options from the list CombatMenu. However, it returns the error: Error running script: Unknown object or variable 'CombatMenu'.
Now, I've done a few things where the string list is created, objects are added to it, and then it's displayed in a menu in the same script (i.e. "verb object" rather than "use object" then "verb object"). So is there any way to create and add to a list that is remembered by the game? Sorry if my question is a bit unclear; basically, how can I get Quest to add variables to a list when one action is taken, and then display a menu containing that list when a separate action is taken?

And secondly, I need a functional combat system after the whole string-list bug is ironed out. When a player attacks an enemy (as in, use the verb attack on an enemy), my goal is to display a menu consisting of all of the skills the player knows for combat. After they choose a skill from that list, they do damage based on what they chose, and then the enemy does damage based on a random number generator that generates a number between 1-6 (to deal 0-5 points of damage). The number generator/damage health script works perfectly on the enemy's end, but I cannot for the life of me figure out how to give my enemy a health attribute, and then reduce it throughout the course of the game. After a lot of failed attempts, here's what I have so far:



That's just the stuff that I know will work. In a previous attempt, I had tried to set a new variable called "enemyhealth" equal to fifty, and then add an "If..." script that would delete the enemy if its health was below 1. However, I wasn't able to find anything that could reduce a pre-established variable. Again, I'm probably not being super clear, but how could I set an enemy's health to a certain number, reduce it by certain amounts, and then hide that enemy when its health is less than zero?

Thanks in advance for any help! :)

EDIT: Also, attached is my game if you want to poke around with it.

jaynabonne
01 Dec 2012, 22:30
I see something running through both of your questions. Let's tackle the first one first.

A word about variables: a simple variable name used in a script, one which is not an object or an attribute of an object, is always a local variable to that script. In other words, it only exists within that script, and it goes away when the script exits. As you discovered, while you remain within the script, the variable exists. Once it exits... poof! And same named variables used in different scripts are actually different, unrelated variables.

What you need is a global place to store your data. You almost (perhaps accidentally) got the answer in your question: "So is there any way to create and add to a list that is remembered by the game?"

The answer is to store the list as an attribute of the global game object (you could also store it as an attribute of the player). Instead of using CombatMenu, use game.CombatMenu. The former is a local variable. The latter is a persistent attribute of the game object.

Keep in mind that if you do "new string list" every time you learn a new skill, then you will wipe out the old list. So you will need to check if the list already exists. If it does, then move onto to setting the new skill. Else create it first.

Your second question seems similar. You want a way to associate a value with the enemy. The answer is the same: use an attribute. You can create an integer attribute (for example) on the enemy, and then decrease it by your "dmg" amount. If the value goes to zero or negative, then move the enemy off to some hidden room (I call mine "Limbo" typically) so the player can no longer see it.

Hope that helps!