Labeling Objects (solved)

chaosp
23 Mar 2018, 16:51

Hello I was wondering whether there is a way to label an object for future reference. For example, I would like to label orc1 as "enemy", so that anytime I call a function such as Hit (enemy) it acts on orc1. Then in the next room if I label orc2 as "enemy" the Hit(enemy) function would hit orc2. I've tried the obvious orc1=enemy, which doesn't work.

I managed to construct a work-around by creating an object called "enemy" and transferring any required attributes from the desired object to it (for example by setting enemy.health=orc1.health), and then having the player interact with this "enemy" object. However it is a bit time consuming and inelegant to do it this way, so any help finding a simpler solution would be appreciated.

Many thanks.


K.V.
23 Mar 2018, 17:11

You were close!

orc1.enemy = true

Io
23 Mar 2018, 18:57

I'm actually doing something like this for my game! I have team fights, with up to 4 enemies vs the player and 3 AI controlled allies. What I do is I have an object attribute for the player called 'Target'. I have a bunch of code that decides who the target is depending on input, and then carries attacks like that. It's great for setting things like target health too. You can get REALLY fancy with object attributes. In psuedocode:

set Player.Target=orc1
set Player.Target.Health=Player.Target.Health-Player.DamagePlayerDealsWithAttack
if (Player.Target=orc1){
print "The orc says oof!"
}
else if (Player.Target=orc2){
print "The orc grunts as you hit him."
}

chaosp
23 Mar 2018, 19:01

Hi, thank you for the swift reply. I don't think i set out my problem very well in my first post. A more detailed version of what I'm trying to achieve is:

Player types "hit orc1". This calls the function Hit with variable "object", i.e.Hit(object) occurs running the hit script. The object in this case is orc1. Unfortunately once the hit script is over the code obviously no longer remembers the "object" in Hit(object) as orc1.

Thus as part of the hit script I would somehow like to label (or rename) any object hit as "enemy" . Thus if orc1 hits back, the combat script can use attributes such as enemy.fightskill. This means when I come to another enemy (eg orc2) and Hit them, the script will then label that object as "enemy" and the combat script can still use enemy.fightskill without having to specifically refer to orc2.

If I understand correctly k.v.'s script would give orc1 the boolean attribute orc1.enemy =true and I'm not sure how I would use that when calling a function. Could you check the room for any object where object.enemy=true and then obtain the required object's attributes from there?

Many thanks for the help so far, this is the most stuck i've been with Quest yet!


chaosp
23 Mar 2018, 19:22

Thank you Io, thats exactly what I was looking for! That's a much better method than I was using before! All my scripts now run happily. Thanks again.


Io
23 Mar 2018, 19:22

Edit: Whoops, nevermind. You read my thing before I typed this.