Making a Special "use" Command For a Created Object
jmnevil54
03 Oct 2018, 04:13I am making a use command for an object, or at least I am trying to. I copied some code from The Pixie, and I have a scipt that creates an object. I thought making a use command would be like object.use or something, but it wasn't.
This is my code.
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.inventory
obj.displayverbs = Split("Look at;Drop;Use;Take", ";")
obj.alias = "Pokeball"
obj.look = ProcessText("A " + obj.alias + ", use it.")
obj.use => {
player.catchrate = player.catchrate + 1
}
How do I improve this code? How do I make a special command, maybe verb? Should I give up and use attributes instead? And can I modify take for this object too?
The Pixie
03 Oct 2018, 07:36"use" is indeed a script attribute, object.use
. Because it is built in you have to use it that way. But the code you have should work.
However, you have a line:
obj.parent = player.inventory
Does the player have a special object called "inventory" where things are kept? If not, then it should be:
obj.parent = player
Also, Quest uses one list when the player is holding the item, another when it is in the room, so these two would work better:
obj.displayverbs = Split("Look at;Take", ";")
obj.inventoryverbs = Split("Look at;Drop;Use", ";")
jmnevil54
03 Oct 2018, 13:48I'll try it. Thanks.
mrangel
03 Oct 2018, 17:12How do I improve this code?
if (HasInt(game, "pokeballcount")) { game.pokeballcount = game.pokeballcount + 1 } else { game.pokeballcount = 1 } create ("pokeballcount" + game.pokeballcount) obj = GetObject("pokeballcount" + game.pokeballcount)
This seems to be quite a big chunk of code. Do you need the pokeballcount
attribute later on? If not, you could probably make it easier to maintain by using one of the core functions::
objname = GetUniqueElementName("pokeball")
create (objname)
obj = GetObject (objname)
obj.parent = player.inventory
I think someone already mentioned that the .inventory
is probably an error.
obj.displayverbs = Split("Look at;Drop;Use;Take", ";")
All this does is adds "Drop" to the verbs menu when you're not holding the object. You could replace this with the two lines Pixie suggested, or you could just remove it (because the defaultobject
type's displayverbs are "Look At;Take" and its inventoryverbs are "Look At;Use;Drop". If you want to add other displayverbs, you should list them separately like Pixie suggested, but if you just want the default verbs, you can omit them.
obj.look = ProcessText("A " + obj.alias + ", use it.")
The call to ProcessText does nothing because there are no text processor commands in that string. You can just put:
obj.look = "A " + obj.alias + ", use it."
or even
obj.look = "A Pokeball, use it."
obj.use => { player.catchrate = player.catchrate + 1 }
This sets up a use
verb, which should work. However, it seems a little odd. If the player types "use pokeball", the game increases their catchrate stat by 1. So what's to stop them just using the ball a hundred times before they try to catch anything?
If this is just placeholder code, then you probably already fixed that issue.
How do I make a special command, maybe verb?
I think you already know how to make a command. If you mean you want to add a verb to the object you're creating, you should look for the verb definition. For example, if you want to be able to throw the ball you're creating, look for the 'throw' verb in your game. In full code view it looks like this:
<verb name="throw">
<pattern>throw #object#</pattern>
<property>throw</property>
<defaulttemplate>DefaultThrow</defaulttemplate>
</verb>
The line you're interested in is <property>throw</property>
. This tells you that to make an object throwable, you would need to do something like:
obj.throw => {
// Insert code here
}
For most verbs, the property is probably the same as the verb, but it isn't always, so it's a good idea to check.
And can I modify take for this object too?
Yep. Just set the take
attribute to be a script.
obj.take => {
// some script here
}
This isn't quite the same as a verb; because you can also set the obj.take
attribute to true
(object can be taken normally) or false
(displays the default message to say it can't be taken).