Can you compare an obj.alias against a "string" in an if condition?
foxtrotoblivion
22 Aug 2021, 06:25I'm trying to find a way to have my spawnenemy function (from the Quest zombie tutorial) change the hitpoints of the monster based on the name of the enemy.alias. The issue in question is the last couple lines, when I switch out (game.crittercount = 1) with (slime.alias = "berry") it always comes out false when slime.alias is set "berry".
This is in the spawnenemy function
if (HasInt(game, "crittercount")) {
game.crittercount = game.crittercount + 1
}
else {
game.crittercount = 1
}
create ("critter" + game.crittercount)
slime = GetObject("critter" + game.crittercount)
slime.parent = room
slime.displayverbs = Split("Look at;Ingest", ";")
slime.dead = false
slime.changedhitpoints => {
if (this.hitpoints < 1) {
msg ("You devoured it!")
this.dead = true
this.parent = null
}
}
names = Split("honey;berry;syrup;sludge", ";")
slime.alias = StringListItem(names, game.crittercount % ListCount(names)) + " slime"
slime.listalias = CapFirst(slime.alias)
slime.look = ProcessText("A " + slime.alias + ", {random:Large and slimy:Dripping with juice:Big and flabby}.")
if (game.crittercount = 1) {
slime.hitpoints = 10
}
else {
slime.hitpoints = 30
}
If there is a more efficient way of doing this I'd love some advice.
mrangel
22 Aug 2021, 09:35when I switch out (game.crittercount = 1) with (slime.alias = "berry") it always comes out false
If the alias is "berry" then if (slime.alias = "berry") {
should work fine. But…
slime.alias = StringListItem(names, game.crittercount % ListCount(names)) + " slime"
The alias will never be "berry", so your condition will always be false. This line sets the alias to one of "honey slime", "berry slime", "syrup slime", or "sludge slime"
foxtrotoblivion
22 Aug 2021, 10:13I'm pretty new to coding and having a second pair of eyes helped out. I would have been stuck for a while re-re-re-reading through code. Thank you.