More problems with creating object

Hey, I'm having problems creating pokeballs again.

  1. Should I use a name or expression for the "destory" function? Do I use obj, this, or object?
  2. I am unable to take the object, but I can drop it.

My code.

player.pokedollar = player.pokedollar - 5000
if (HasInt(game, "pokeballcount")) {
  game.pokeballcount = game.pokeballcount + 1
}
else {
  game.pokeballcount = 1
}
create ("pokeballcount" + game.pokeballcount)
obj = GetObject("pokeballcount" + game.pokeballcount)
obj.parent = player
obj.displayverbs = Split("Look at;Use;Take", ";")
obj.inventoryverbs = Split("Look at;Drop;Use", ";")
obj.alias = "Pokeball"
obj.look = "A " + obj.alias + ", a device that aids in catching Pokemon. Use it."
obj.use => {
  player.catchrate = player.catchrate + 1
  destroy ("this")
}

the 'destroy (XXX)' Function takes/uses the Object's string name:

http://docs.textadventures.co.uk/quest/scripts/destroy.html

// create ("NAME_OF_OBJECT")

destroy ("NAME_OF_OBJECT")
// or
destroy (NAME_OF_OBJECT.name)
// or
object_variable = NAME_OF_OBJECT
destroy (object_variable.name)
// or
string_variable = NAME_OF_OBJECT.name
destroy (string_variable)


player.pokedollar = player.pokedollar - 5000
if (HasInt(game, "pokeballcount")) {
  game.pokeballcount = game.pokeballcount + 1
}
else {
  game.pokeballcount = 1
}

// --------------------------------------------

// just to be safe that it works:

string_variable_1 = ToString (game.pokeballcount)
string_variable_2 = "pokeballcount" + string_variable_1
object_variable = create (string_variable_2)

// but this (what you had --- with slight edit: in storing it into a Variable) probably works fine:

object_variable = create ("pokeballcount" + game.pokeballcount)

// if not, then try this:

object_variable = create ("pokeballcount" + ToString (game.pokeballcount))

// if still not, then use the 'just to be safe that it works' code above

// -------------------------------------------

object_variable.parent = player
object_variable.take = true
object_variable.displayverbs = Split("Look at;Use;Take", ";")
object_variable.inventoryverbs = Split("Look at;Drop;Use", ";")
object_variable.alias = "Pokeball"
object_variable.look = "A " + object_variable.alias + ", a device that aids in catching Pokemon. Use it."
object_variable.use => {
  player.catchrate = player.catchrate + 1
  destroy (object_variable.name)
}

if you want your code to stay (mostly) the same as you had it, then you can use this code:

player.pokedollar = player.pokedollar - 5000
if (HasInt(game, "pokeballcount")) {
  game.pokeballcount = game.pokeballcount + 1
}
else {
  game.pokeballcount = 1
}
obj = create ("pokeballcount" + game.pokeballcount) // or: see above on alternative scripting
obj.parent = player
obj.take = true
obj.displayverbs = Split("Look at;Use;Take", ";")
obj.inventoryverbs = Split("Look at;Drop;Use", ";")
obj.alias = "Pokeball"
obj.look = "A " + obj.alias + ", a device that aids in catching Pokemon. Use it."
obj.use => {
  player.catchrate = player.catchrate + 1
  destroy (obj.name)
}

I tried the second thing that you said, and I got:
Error running script: Element not found: 'object.name'

I still need to figure out what to do for "take."


  1. You need the name of the object. You can't use obj.name like HK suggested, because the variable obj is only in scope as long as the creation function is running.

    What you want is: destroy (this.name)

  2. To let the player take an object, you need to set obj.take = true. I think I pointed this out on the last version of this code you shared.


To let the player take an object, you need to set obj.take = true. I think I pointed this out on the last version of this code you shared.
Sorry, I missed it. Anyways, thank you!


(filler for getting my edited post, updated/posted)


oops my bad, sorry jmnevil! (thank you for correcting and explaining my mistake, mrangel!)

I wasn't paying attention to this part of code of mine:

obj.use => {
  player.catchrate = player.catchrate + 1
  destroy (obj.name)
}

the 'obj' isn't defined (its not storing the Object reference/pointer) for within its nested scripting... so that's why the error

outside of the 'obj.use' Script Attribute: obj = YOUR_OBJECT: no error
inside of the 'obj.use' Script Attribute: obj = ??? (null): ERROR!!!!


a quick-easy fix for it:

game.stored_object = obj

obj.use => {
  player.catchrate = player.catchrate + 1
  destroy (game.stored_object.name)
}

and the full fixed code:

player.pokedollar = player.pokedollar - 5000

if (HasInt(game, "pokeballcount")) {
  game.pokeballcount = game.pokeballcount + 1
} else {
  game.pokeballcount = 1
}

obj = create ("pokeballcount" + game.pokeballcount) // or: in my previous post, see above on alternative scripting

obj.parent = player

obj.take = true // sorry, I had this line of code between the other code lines in my previous post, so easy to miss it, but now I've separated it out in this post, so you can see it this time

obj.displayverbs = Split("Look at;Use;Take", ";")
obj.inventoryverbs = Split("Look at;Drop;Use", ";")

obj.alias = "Pokeball"

obj.look = "A " + obj.alias + ", a device that aids in catching Pokemon. Use it."

game.stored_object = obj

obj.use => {
  player.catchrate = player.catchrate + 1
  destroy (game.stored_object.name)
}

@HK:
That makes no sense. You've got a script to create consumable objects, but you're using a global attribute to store a reference to the last one created?

The only sensible way to handle that change is to use this within the script attribute. As in:

obj.use => {
  player.catchrate = player.catchrate + 1
  destroy (this.name)
}

... which is the answer I already gave.


...smacks head...

...I need to pay more attention...

(we've had too many posts needing help with the issue of using nesting 'this' scope issue, wanting/needing/using a non-parent Object)

... I need to pay more attention

it's a Script Attribute and the Object we want is its parent for this case, so indeed, we can use 'this'

I was just using an Attribute, which would be the quick-fix, if we weren't using the parent Object of a Script Attribute (weren't able to use 'this')...

as I wasn't paying attention...

... smacks head...


/me puts a band-aid on HK's head.


I got a very hard dense head (and am very hard headed), so don't worry, my head is quite fine... now the desk or hand or wall that I smacked my head against is... broken...


Now I'm getting:
Error running script: Element not found: 'this.name'

Maybe my game just doesn't like me...


That sounds like you've put:
destroy ("this.name")
instead of
destroy (this.name)


Strange. When I looked at it it said destroy-name-this.name, and the code was destroy ("this.name"), then when I changed it to destroy (this.name) it became destory-expression-this.name. I'll play it when I have time. Thank you.


Log in to post a reply.

Support

Forums