Combat-Enemy health?

LOTW
I'm trying to figure everything out before I start on a real game, and this is the only problem I have found at the moment that I haven't found a solution to. Basically, the player is supposed to hit a monster before it kills them. I have a simple timer system set up to do this, as well as a one-hit system for killing the monster. I would like to give different monsters different amounts of health, instead of them all being easy to kill. If possible, I would also like to be able to make different objects take more or less health.

Please explain how to do this without going into Code View, as I said I am just starting and I don't understand code yet.

adammadam
give the monster an attribute called health, set it to integer and to the value you want (e.g. 100). Give the player an attribute called damage and set it to integer and the value you want (e.g. 20). Then you can have a verb or command to attack the monster. When the player attacks use a set attribute script and have it like this monster.health = monster.health - player.damage

If you look on the forums there is a topic called "Basic combat help" a bit farther down but on the first page of threads where I learnt how to do this as well.

LOTW
I tried to do what you said but I started getting an error message whenever I try to test play the game. I couldn't find what was wrong. Thanks anyway.

jaynabonne
It might be a simple problem. If you can post the game or the code you tried, we can help you work it out.

HegemonKhan
an example:

'player' Player Object -> 'Attributes' Tab -> Attributes -> Add -> (see below, repeat as needed)

(Object Name: player)
Attribute Name: damage
Attribute Type: int (integer)
Attribute Value: 100

(Object Name: player)
Attribute Name: current_life
Attribute Type: int
Attribute Value: 999

(Object Name: player)
Attribute Name: maximum_life
Attribute Type: int
Attribute Value: 999

'room' Room Object -> 'Objects' Tab -> Add -> Name: orc

'orc' Object -> 'Attributes' Tab -> Attributes -> Add -> (see below, repeat as needed)

(Object Name: orc)
Attribute Name: damage
Attribute Type: int
Attribute Value: 50

(Object Name: orc)
Attribute Name: current_life
Attribute Type: int
Attribute Value: 500

(Object Name: orc)
Attribute Name: maximum_life
Attribute Type: int
Attribute Value: 500

(Object Name: orc)
Attribute Name: dead
Attribute Type: boolean
Attribute Value: false

'orc' Object -> 'Verbs' Tab -> Add -> Name: fight -> [run a script] -> (see below)

add new script -> scripts -> 'if' Script -> if [expression] orc.dead
-> then -> add new script -> output -> 'print a message' Script -> print [message] The orc is already dead, silly.
add else -> add new script -> variables -> 'set a variable or attribute' Script -> set variable orc.current_life = [expression] orc.current_life - player.damage
-> add new script -> output -> 'print a message' Script -> print [expression] "You attack the orc, doing {player.damage} damage, leaving the orc with {orc.current_life} life left."
-> add new script -> scripts -> 'if' Script -> if [expression] orc.current_life <= 0
->-> then -> add new script -> variables -> 'set a variable or attribute' Script -> set variable orc.dead = [expression] true
->-> add new script -> output -> 'print a message' Script -> print [message] You killed the orc!
-> add else -> add new script -> variables -> 'set a variable or attribute' Script -> set variable player.current_life = [expression] player.current_life - orc.damage
->-> add new script -> output -> 'print a message' Script -> print [expression] "The orc attacks you, doing {orc.damage} damage, leaving you with {player.current_life} life left."
->-> add new script -> scripts -> 'if' Script -> if [expression] player.current_life <= 0
->->-> then -> add new script -> output -> 'print a message' Script -> print [message] The orc killed you.
->->-> add new script -> output -> 'print a message' Script -> print [message] GAME OVER
->->-> add new script -> game state -> 'finish the game' Script


------------

if you want to know how to display: (Player's) Life: 999/999

and also in the 'orc' Object's 'fight' Verb, if you want to message the 'current/maximum' of the orc's life and player's life, let me know. (I'm tired right now, lol)

and also, if you want 'life restore potion' Objects, partially and~or fully restoring your life, let me know (this is the one of the real reasons for creating~adding~using~having the 'maximum_life' Integer Attribute). Again, let me know.

adammadam
LOTW wrote:I tried to do what you said but I started getting an error message whenever I try to test play the game. I couldn't find what was wrong. Thanks anyway.


copy the screenshots in this topic viewtopic.php?f=10&t=5278

If you get error messages you haven't done something, for example if you don't give the monster and the player their attributes, then it will give an error, if you spell them wrong or write them out in the incorrect format it will give an error etc.

So you can see from the screenshots I used the word vitality instead of health.. but the word doesnt matter, you can use any word, just make sure it's consistent. e.g. if you call it "life" you would give the monster an attribute called life, set to integer, to a value you want (e.g. 100) then you'd have monster.life = monster.life - player.damage

adammadam
download/file.php?id=1218

adammadam
and here is the tutorial on how to add attributes.. in the tutorial they use weight as an example, of course you can use what you want like health, damage.. whatever.. instead of weight. http://docs.textadventures.co.uk/quest/ ... butes.html

Whatever attribute you add is what your script will try to use.. so if you have monster.life = monster.life - player.damage it will search for an attribute called damage for the player and for an attribute called life for the monster, if they are missing, it won't work and will give an error, so you have to add these attributes also in the way the tutorial shows.

HegemonKhan
also another possible cause of the error, he~she may not have an Object named 'monster', yet be trying to literally use our 'monster.life = monster.life - player.life'. They got to match up the Object's 'name' too, along with their Attribute's 'name, as well.

if you can tell us what the error message~code is saying, (and~or best of all: post your entire game code ~ if you don't mind doing so publically, or if you do mind, then pm it to one of the site's moderators, and them can help you privately), then we can better troubleshoot for you, fixing your coding error(s).

don't be scared of any errors, including errors that prevent you from even playing your game or just getting into the GUI~Editor of~for your game. The errors are just mistakes that you made, which can be fixed, as you can always open up your game file, via a text software (notepad, wordpad, etc), and fix the coding mistake(s) you've made. Unless you mess up with the underlying~engine code... but hopefully you know not to mess with it and don't mess with it, until you're able to do so, lol.

LOTW
Thank you everybody. Unfortunately, I tried these solutions, and most of the time I got lost part of the way through. The only one I got through was the one that gave me the error (after going through the entire game twice, I could not find the cause of the error,so I deleted all the code related to it to start over. Sorry I didn't think to copy the error message.) Working through the game during this did give me an idea of a possible way to fix the problem, though. I had nearly finished, but the computer shut off on me so I'll have to redo it. I'll post the screenshots of it tomorrow.

HegemonKhan
if you want... make a new game, and try to go through this example guide post of mine:

viewtopic.php?f=10&t=5340&p=36991#p36976

(hopefully if~once you can do this example, you'll have an understanding of how it is done from this example, and can set up your own stuff in your game)

(the likely-est source of errors is not choosing the correct 'add a~new script' circle buttons... one of the reasons I don't like using the GUI~Editor lol... my '->' arrows try to help show you the correct indenting ~ the correct 'add a~new script' circel buttons to click on, for your script block to work properly~correctly, without any errors)

I can help you then with getting it all done properly.

adammadam
look open this game and copy this

LOTW
HegemonKhan, I tried to copy it and it's showing "Error running script: Error compiling expression 'orc.current.life - player.damage': Object reference not set to an instance of an object." I'm almost sure I copied it exactly.

jaynabonne
Based on the message, it looks like you have "orc.current.life" instead of "orc.current_life"

LOTW
You were right, I found the "orc.current.life" and fixed it, but now it's showing an error "Error running script: Error compiling expression 'orc.current_life - player.damage': AritmeticElement: Operation 'Subtract' is not defined for types 'Object' and 'Int32'

jaynabonne
That's telling you that "orc.current_life" doesn't exist. Did you do this part:

(Object Name: orc)
Attribute Name: current_life
Attribute Type: int
Attribute Value: 500

LOTW
I misspelled it when I put it in. It all seems to be working now. One last thing, When the orc is killed it says 'You killed the orc', which is good, but when I try to fight it again after killing it it repeats after saying 'The orc is already dead'. How do I stop it from repeating?

HegemonKhan
that is~was the intent, lol. You can't fight a dead orc (you don't fight dead rotting corpses!)..., hence the message telling you so, hehe :D

you could remove that 'if' condition (but why do you want to keep fighting the orc over and over ???), see how here for how'd you do this (compare this to the previous code block in my previous post):

add new script -> variables -> 'set a variable or attribute' Script -> set variable orc.current_life = [expression] orc.current_life - player.damage
add new script -> output -> 'print a message' Script -> print [expression] "You attack the orc, doing {player.damage} damage, leaving the orc with {orc.current_life} life left."
add new script -> scripts -> 'if' Script -> if [expression] orc.current_life <= 0
-> then -> add new script -> output -> 'print a message' Script -> print [message] You killed the orc!
add else -> add new script -> variables -> 'set a variable or attribute' Script -> set variable player.current_life = [expression] player.current_life - orc.damage
-> add new script -> output -> 'print a message' Script -> print [expression] "The orc attacks you, doing {orc.damage} damage, leaving you with {player.current_life} life left."
-> add new script -> scripts -> 'if' Script -> if [expression] player.current_life <= 0
->-> then -> add new script -> output -> 'print a message' Script -> print [message] The orc killed you.
->-> add new script -> output -> 'print a message' Script -> print [message] GAME OVER
->-> add new script -> game state -> 'finish the game' Script


or you could make a 'revive potion~spell' Object, which its 'use revive potion on orc~cast revive spell on orc' Verb brings the orc back to life, via:

run as~a script -> add a~new script -> 'set a variable or attribute' Script -> set variable orc.dead = [expression] false

and now, you can fight the orc again :D

---------

Boolean Attribute (in code):

Object_name.Attribute_name = true_or_false

logic conceptuality:

orc.dead=true ---> the orc is dead.
orc.dead=false ---> the orc is alive.
if (not orc.dead=true) ---> the orc is alive.
if (not orc.dead=false) ---> the orc is dead.

orc.alive=true ---> the orc is alive.
orc.alive=false ---> the orc is dead.
if (not orc.alive=true) ---> the orc is dead.
if (not orc.alive=false) ---> the orc is alive.

(you choose~use one name or the other, in this example 'dead' or 'alive', not both, as there's no reason: redundency + illogical)

LOTW
What I mean is that it says 'You killed the orc' over and over. I do want it to say if the orc is dead, but I would like if that message only showed once, after you first kill it.

jaynabonne
The problem with the original code is that it uses "orc.dead" to bypass normal combat. Unfortunately, I couldn't see any place in the code where it ever sets orc.dead to true, so it keeps trying to fight the orc over and over, you keep killing it, and it keeps getting more and more dead. Where it says "You killed the orc", you need to add a line to set "orc.dead" to true or something like that.

Or more easily, change "orc.dead" in the "if" to use "orc.current_life <= 0" instead. That's the same condition used to determine the orc had been killed.

HegemonKhan
@Jay:

I think you're looking at this (see link below), where I took out the related lines, as I thought LOWT didn't want the 'if (orc.dead) { msg ("The orc is already dead, silly") }', (as seen in his~her responding post: viewtopic.php?f=10&t=5340&start=15#p37022 : "... when I try to fight it again after killing it it repeats after saying 'The orc is already dead'. How do I stop it from repeating? (LOWT)", which I responded to, as seen below) :

viewtopic.php?f=10&p=37037#p37024

add new script -> variables -> 'set a variable or attribute' Script -> set variable orc.current_life = [expression] orc.current_life - player.damage
add new script -> output -> 'print a message' Script -> print [expression] "You attack the orc, doing {player.damage} damage, leaving the orc with {orc.current_life} life left."
add new script -> scripts -> 'if' Script -> if [expression] orc.current_life <= 0
-> then -> add new script -> output -> 'print a message' Script -> print [message] You killed the orc!
add else -> add new script -> variables -> 'set a variable or attribute' Script -> set variable player.current_life = [expression] player.current_life - orc.damage
-> add new script -> output -> 'print a message' Script -> print [expression] "The orc attacks you, doing {orc.damage} damage, leaving you with {player.current_life} life left."
-> add new script -> scripts -> 'if' Script -> if [expression] player.current_life <= 0
->-> then -> add new script -> output -> 'print a message' Script -> print [message] The orc killed you.
->-> add new script -> output -> 'print a message' Script -> print [message] GAME OVER
->-> add new script -> game state -> 'finish the game' Script

---

whereas, in my original~prior~previous code (see below), I have the needed lines:

viewtopic.php?f=10&t=5340#p36976

add new script -> scripts -> 'if' Script -> if [expression] orc.dead
-> then -> add new script -> output -> 'print a message' Script -> print [message] The orc is already dead, silly.
add else -> add new script -> variables -> 'set a variable or attribute' Script -> set variable orc.current_life = [expression] orc.current_life - player.damage
-> add new script -> output -> 'print a message' Script -> print [expression] "You attack the orc, doing {player.damage} damage, leaving the orc with {orc.current_life} life left."

-> add new script -> scripts -> 'if' Script -> if [expression] orc.current_life <= 0

->-> then -> add new script -> variables -> 'set a variable or attribute' Script -> set variable orc.dead = [expression] true

->-> add new script -> output -> 'print a message' Script -> print [message] You killed the orc!

-> add else -> add new script -> variables -> 'set a variable or attribute' Script -> set variable player.current_life = [expression] player.current_life - orc.damage
->-> add new script -> output -> 'print a message' Script -> print [expression] "The orc attacks you, doing {orc.damage} damage, leaving you with {player.current_life} life left."
->-> add new script -> scripts -> 'if' Script -> if [expression] player.current_life <= 0
->->-> then -> add new script -> output -> 'print a message' Script -> print [message] The orc killed you.
->->-> add new script -> output -> 'print a message' Script -> print [message] GAME OVER
->->-> add new script -> game state -> 'finish the game' Script

------------------------

@LOWT:

LOWT wrote:I would like if that message only showed once, after you first kill it.


then, don't keep clicking on the 'fight' hyperlink~button...

The 'You already killed the orc, silly" message is a way of informing the person playing of the blocking the 'fight' scripting from activating (as the orc is dead). I guess if you really want to, I suppose you could do~use the 'firsttime~otherwise' Script, so that you only get that message the first time you click on 'fight' of the dead orc, or your other option is to just not have any message at all (but that will confuse the person playing the game, as they click on 'fight' of the dead orc, but nothing happens... you need to tell them why, as it may not be intuitive for them... orc is dead... you can't fight it anymore, lol).

jaynabonne
Yep, you're absolutely correct - the code is there. I must have missed it somehow! (I was looking at the right one, but... who knows.)I even copied the "code" out and did a search, but it must be yet another one of those days. lol

Given the behavior LOTW described (it saying you kill the orc over and over, not the "already killed" one), there must be something else wrong in the way your code got implemented in his/her game.

HegemonKhan
nah, that format is really hard to read (I have trouble with it too, lol and its my own writing+format, lol)...

(being able to write~post code is so much better than trying to give the steps for using the GUI~Editor, sighs).

-----

I think LOTW meant 'the orc is already dead, silly.' message, and not the message of 'You killed the orc!'.

or he's~she's now using that edited newer (bad) code of mine, and thus can keep fighting the dead orc, getting the 'You killed the orc!' over and over (until the player's life hits <= 0, as the game ends, lol).

LOTW
I think I may have been a bit confusing. When I tested fighting the orc after killing it, to make sure it was working, it said 'The orc is already dead. You killed the orc!' I would like to keep the part that says 'The orc is already dead.', and make the part that says 'You killed the orc!' to only show after you first kill it.

jaynabonne
It sounds like the translation from HK's code to your code has failed. It shouldn't be repeating the "You killed the orc!" part, as that should be in the "else" for if (orc.dead), and so it should not be showing up. I don't see how to resolve this other than seeing the code you have entered to find out where the error is. I suspect there is an "else" nesting problem somewhere, where you only have part of what's supposed to be in the else actually in the else. Basically everything after the "if (orc.dead)'s else should be inside that else, as far as I can tell.

HegemonKhan
ya, from what LOTW just posted, that definately sounds like he~she clicked on the wrong 'add a~new script' circle buttons, sounds like just a placement ('nesting'~indenting) issue, causing an incorrect 'order of operations' of the scripting.

in code, your 'orc' Object's 'fight' Verb should be~look like this (I just typed this in on the fly right now, so hopefully there's no mistakes~errors, lol)

if (orc.dead) {
msg ("You killed the orc already, silly.")
} else {
orc.current_life = orc.current_life - player.damage
msg ("You attack the orc, doing {player.damage} damage, leaving it with only {orc.current_life} life left.")
if (orc.current_life <= 0) {
orc.dead = true
msg ("You killed the orc!")
} else {
player.current_life = player.current_life - orc.damage
msg ("The orc attacks you, doing {orc.damage} damage, leaving you with only {player.current_life} life left.")
if (player.current_life <= o) {
msg ("The orc killed you.")
msg ("GAME OVER")
finish
}
}
}


and your (LOTW's) code, due to him~her accidentally (not his~her fault as it is quite difficult) clicking on the wrong 'add a~new script' circle buttons, maybe looks something like this, for example:

if (orc.dead) {
msg ("You killed the orc already, silly.")
}
orc.current_life = orc.current_life - player.damage
msg ("You attack the orc, doing {player.damage} damage, leaving it with only {orc.current_life} life left.")
if (orc.current_life <= 0) {
orc.dead = true
msg ("You killed the orc!")
} else {
player.current_life = player.current_life - orc.damage
msg ("The orc attacks you, doing {orc.damage}, leaving you with only {player.current_life} life left.")
if (player.current_life <= o) {
msg ("The orc killed you.")
msg ("GAME OVER")
finish
}
}


it's really hard (for me anyways) to line up or click on the proper 'add a~new script' circle buttons wit using the GUI~Editor. This is one of the reasons I went to learning to work with code, as textual indenting is much easier for me than figuring out the 'nesting' (indenting) of the GUI~Editor's 'add a~new script' and its script box nesting, again for me I had a very difficult time with it.

-----------

@LOWT:

think of the placement~'nesting'~indenting~'add a~new script circle buttons', like an outline:

I. xxx
A. xxx
1. xxx
a. xxx
2. xxx
a. xxx
B. xxx
1. xxx
a. xxx
2. xxx
a. xxx
II. xxx
A. xxx
1. xxx
a. xxx
2. xxx
B. xxx


so by not clicking on the correct 'add a~new script' circle button(s), you can get a faulty outline (a fault 'order of operations' of the scripting):

I. xxx
A. xxx
1. xxx ---> II. xxx
a. xxx ---> A. xxx (and etc adjustment for the rest of the outline below, making it not what you wanted it to be)
2. xxx
a. xxx
B. xxx
1. xxx
a. xxx
2. xxx
a. xxx
II. xxx ---> III. xxx
A. xxx
1. xxx
a. xxx
2. xxx
B. xxx


the GUI~Editor's 'add a~new script' circle buttons and its script boxes UI setup, are hard to figure out ~ line up correctly:

(pretend that the below my-representation attempt of the GUI~Editor's UI as I can't post a pic~screenshot of it, is what you're seeing, looking at, working with, as the GUI~Editor's UI)

'add a~new script' circle button
'if' -> 'add a~new script' circle button
-> 'add a~new script' circle button
-> 'if' -> add a~new script' circle button
->-> 'add a~new script' circle button
-> 'else if' -> 'add a~new script' circle button
->-> 'add a~new script' circle button
-> 'else' -> 'add a~new script' circle button
->-> 'add a~new script' circle button'
'else if' -> 'add a~new script' circle button
-> 'add a~new script' circle button
'else' -> 'add a~new script' circle button
-> 'add a~new script' circle button
'add a~new script' circle button


this is very confusing in trying to figure out what buttons you need to click on, for the proper 'nesting' (placement~indentation~'order of operations').

I know what I'm doing (as does anyone who learned to work with the code), but I still mess up when I try to work with the 'add a~new script' circle buttons and script boxes of the UI within the GUI~Editor, not clicking on the right button, and~or it takes me a few minutes to figure out exactly what button belongs to what script box (nesting level), aka if the button is inside or outside of the script box (script chain~block) and even what script box.

-------------

(and then there's the whole other issue~beast of~with bloody deleting scripts... its so easy to delete a lot of your scripting, an entire script box or mutliple script box chains~blocks, instead of just that single script line box you wanted to delete ... in the GUI~EDitor, argh!)

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums