Better way to level?

Game http://textadventures.co.uk/games/view/kmwqh7zyrkcrseuqrzuigg/zombie-2
So I was having a hard time with the leveling system for a while. I was usind the code from one of The Pixie's games. I ended up putting the exp and the level function (named love in reference to Undertale) in the SpawnZombie function, and I got it to work that way. But is there a way to get it to work without putting it in the same code I use to spawn zombies?

Level code
Game start script
player.alias = "you"
player.hitpoints = 110
player.damage = 3
player.attack = 0
player.defence = 0
player.armour = 0
player.exp = 0
player.plevel = 0
player.changedhitpoints => {
if (player.hitpoints > 0) {
msg ("Hits points now " + player.hitpoints)
}
else {
msg ("You are dead!")
finish
}
}
spade.damage = "1d6"
spade.attack = 3
pistol.damage = "0"
pistol.attack = 0
pistol.firearmdamage = "2d8"
pistol.firearmattack = 3
pistol.ammo = 7
pistol.ammomax = 6
game.notarealturn = false
game.unresolvedcommandhandler => {
msg ("Er, what..?")
game.notarealturn = true
}
player.attackers = NewObjectList()
player.ammo = 40
player.statusattributes = NewStringDictionary()
dictionary add (player.statusattributes, "hitpoints", "Hit points: !")
dictionary add (player.statusattributes, "ammo", "Spare ammo: !")
dictionary add (player.statusattributes, "equippedname", "Weapon: !")
dictionary add (player.statusattributes, "ammonote", "Ammo: !")
dictionary add (player.statusattributes, "plevel", "plevel: !")
dictionary add (player.statusattributes, "exp", "exp: !")
WeaponUpdate

blah blah
SpawnZombie
if (HasInt(game, "crittercount")) {
game.crittercount = game.crittercount + 1
}
else {
game.crittercount = 1
}
create ("crittercount" + game.crittercount)
obj = GetObject("crittercount" + game.crittercount)
obj.parent = room
obj.displayverbs = Split("Look at;Attack;Shoot", ";")
obj.dead = false
obj.changedhitpoints => {
if (this.hitpoints < 1) {
msg ("It is dead!")
this.dead = true
player.exp = player.exp + 20
love
}
}
names = Split("decipit;decomposing;shambling;disgusting;filthy;falling-apart", ";")
obj.alias = StringListItem(names, game.crittercount % ListCount(names)) + " zombie"
obj.listalias = CapFirst(obj.alias)
obj.look = ProcessText("A " + obj.alias + ", {random:covered in maggots:missing an arm:one eye hanging out}.")
obj.hitpoints = 8
obj.damage = 2
obj.attack = 0
obj.defence = 0
obj.armour = 0

blah blah
love function (level function)
if (player.exp > player.exp * 0.1 + 100) {
player.plevel = 1 + player.plevel
msg (""You are level" + player.plevel")
}


love function (level function)
if (player.exp > player.exp * 0.1 + 100) {
player.plevel = 1 + player.plevel
msg (""You are level" + player.plevel")
I think you got an error here...
player.exp will never be greater than player.exp...
but
if (player.exp > player.plevel * 0.1 + 100)*
will work.
But, as a separate function, it should be in the game code level...
then just called from anywhere...


Well, I've tried "if (player.exp > player.plevel * 0.1 + 100)" but it doesn't seem to matter.
I'll think about it though, thanks.

I just can't get it to work in the game start. I would suppose I could hook up the
"
if (this.hitpoints < 1) {
msg ("It is dead!")
this.dead = true"
somehow. I haven't figured it out.


I would personally start off simple and learning that first, and then slowly building your way up to more complex combat/leveling code. As, I think this is easier than trying to work with someone else's code, which is hard for anyone to understand, compared to creating your own code, which you understand very well.

try creating your own simple damage combat (you attack, monster attacks, until one of you are dead) and see if you can get it to work, then you can work on making it more advanced/complex stuff, such as displayment of line/hits/damage/etc during combat, looting the corpse, leveling up, more complex combat, weapons/armor:/:more complex combat equations/formulas, etc.


for example:

// not using a Function (generally not better to do):

<game name="example_game">
  <attr name="start" type="script">
    <![CDATA[
      player.life = 999
      player.damage = 50
      monster.life = 500
      monster.damage = 10
      while (player.life > 0 and monster.life > 0) {
        monster.life = monster.life - player.damage
        player.life = player.life - monster.damage
      }
      if (player.life < 0 and monster.life < 0) { {
        msg ("The monster and you are both killed")
      } else if (monster.life < 0) {
        msg ("You kill the monster")
      } else {
        msg ("The monster kills you")
      }
    ]]>
  </attr>
</game>

<object name="room">
  <object name="player">
  </object>
  <object name="monster">
  </object>
</object>

---------

// using a Function (generally better to do):

<game name="example_game">
  <attr name="start" type="script">
    example_function
  </attr>
</game>

<object name="room">
  <object name="player">
  </object>
  <object name="monster">
  </object>
</object>

<function name="example_function">
  <![CDATA[
    player.life = 999
    player.damage = 50
    monster.life = 500
    monster.damage = 10
    while (player.life > 0 and monster.life > 0) {
      monster.life = monster.life - player.damage
      player.life = player.life - monster.damage
    }
    if (player.life < 0 and monster.life < 0) { {
      msg ("The monster and you are both killed")
    } else if (monster.life < 0) {
      msg ("You kill the monster")
    } else {
      msg ("The monster kills you")
    }
  ]]>
</function>

there's only two ways of doing 'always/constantly checking' of/for dynamic Attributes in your game, which are:

  1. the 'Turnscript/Timer' Elements
  2. the special 'changedNAME_OF_ATTRIBUTE' Script Attribute

also, about the special 'this' keyword/keycommand:

it GETS its (reference of/to its) parent Object, so you need to understand what you're doing, in order to use 'this' correctly, and/or know when/where/if you can use 'this' or not for what you're trying to do with your coding designs.


Again, I tried putting the code into the start script, and it either didn't work or I got an error.

Quest just doesn't recognize that it recently added 20 to the exp in the SpawnZombie function. So I had to move the code to there.


could you post your 'game' Game Settings Object's 'start' Script Attribute's code (this includes the code you placed in here from Pixie's code) please, as it would be helpful to see exactly what you've got, so we can help you with getting it to work. Also, could you post pixie's 'spawn zombie' Function's code too? as I need to know what you code you've got, so I can help you with fixing it up.

if your game isn't too big, and if you don't mind, it'd be best to post your entire game code, as that's more content for me, to be able to look at and thus help you with fixing it up.

(if we still need it after we take a look at the code above, could you post Pixie's library's code too, as I'm not familiar with it, and am too lazy to download it myself)


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

Support

Forums