Command "aliases"
nanodeath
30 Nov 2015, 03:43I have an object representing a "button" (a regular push-once button, not a toggleable radio-style button), and rather than having the player "use" the button, it'd be more natural to let them "push" the button.
What's the simplest way to have a "push" command specifically for buttons that effectively does the same thing as "use"?
(The http://docs.textadventures.co.uk/quest/tutorial/custom_commands.html page mentions "Alternative command patterns", which is sort of what I want, but not quite).
What's the simplest way to have a "push" command specifically for buttons that effectively does the same thing as "use"?
(The http://docs.textadventures.co.uk/quest/tutorial/custom_commands.html page mentions "Alternative command patterns", which is sort of what I want, but not quite).
HegemonKhan
30 Nov 2015, 05:13the easiest would be to create~add your own Verb for that 'whatever button' Object, naming the Verb 'push' (actually, there might already be a built-in 'push' Verb, not sure off-hand is there is or not), and then choosing whatever the scripts you want for it.
This might be a bit intimidating if you're totally new to quest and especially to coding~programming, but it's really not that bad, we can help you through it, with more information about what you want to do in your game in regards to this topic of yours.
This might be a bit intimidating if you're totally new to quest and especially to coding~programming, but it's really not that bad, we can help you through it, with more information about what you want to do in your game in regards to this topic of yours.

XanMag
30 Nov 2015, 05:16I just copy-paste my use scripts, add the verb push, and paste it there. I let the player either "push the button" or "use the button". Is that what you mean? If not, help me see what you mean, because I use commands a lot especially when there are multiple things a player can type to try and do the same thing.
Or if you want to streamline it into one command, don't toggle the use option under features and just add a command to the proper room that the button is in. For the command type in whatever the player might type to push/use the button. For example, type in the first box under command type: push button; use button; finger button; touch button; depress button; push button with toe
... etc etc
Then just add the scripts you want to have happen.
Here is a dumb command that is under the game branch that I added to X2 just in case someone had the hankering...
Hope that helps.
Or if you want to streamline it into one command, don't toggle the use option under features and just add a command to the proper room that the button is in. For the command type in whatever the player might type to push/use the button. For example, type in the first box under command type: push button; use button; finger button; touch button; depress button; push button with toe
... etc etc
Then just add the scripts you want to have happen.
Here is a dumb command that is under the game branch that I added to X2 just in case someone had the hankering...

<command name="kill me cmd">
<pattern>kill me; commit suicide; bite the bullet; kick the can; die; kill xan; kill blerk; commit suicide</pattern>
<script><![CDATA[
firsttime {
msg ("I realize you are probably kidding and just frustrated, but doing so will severely hinder you ability to beat the game. If you are that frustrated with it, ask on the forums for help, or simply type 'hints' in game and follow those instructions.<br/><br/>If you are adament about killing yourself, go ahead and type it again and I'll see if I can grant your wish.")
}
otherwise {
msg ("You take your Man Card and press sharply againt your throat. You slice with all your might. It draws a little bit of blood but didn't do the job. You continue sawing and slicing for hours until you succeed at removing your head entirely. Well done, chicken.")
DecreaseHealth (100)
finish
}
]]></script>
</command>
Hope that helps.
nanodeath
30 Nov 2015, 06:32Alright, I figured out one possible solution. I created a new command with the pattern "push #object#" with one script that calls "HandleSingleCommand("use " + object.name)". Per http://docs.textadventures.co.uk/quest/functions/ it looks like HandleSingleCommand might be internal API, but eh, it works. It's not perfect, though, since some of the feedback is incorrect now, e.g. "push thing" -> "You can't use it."
To improve that, I changed it over to a verb, taking a hint from HegemonKhan. For the verb itself, it's very standard fare, just "push" as the Pattern and Attribute, with a default blurb "You can't push that!" bit. Then for the button I added the "push" verb and am now having it execute "HandleSingleCommand ("use " + this.name)".
Finally, because I don't want to have ugly "HandleSingleCommand foo" stuff littered around my story, I created a new function "UseAlias" which takes a single parameter "object" and then calls "HandleSingleCommand ("use " + object.name)"
I'm getting "Error running script: Error adding key 'push' to dictionary: An item with the same key has already been added." now though because there is already a "push/pull" verb in the Core...still trying to figure out a way around that.
Otherwise, mostly set. Thank you both for the help!
Edit: With some fiddling, I was able to get that error to go away. I think I had to Copy the Core's "push" verb to my project and then delete it, and then change the attribute of my "push" to...something else, i.e. "pushButton".
To improve that, I changed it over to a verb, taking a hint from HegemonKhan. For the verb itself, it's very standard fare, just "push" as the Pattern and Attribute, with a default blurb "You can't push that!" bit. Then for the button I added the "push" verb and am now having it execute "HandleSingleCommand ("use " + this.name)".
Finally, because I don't want to have ugly "HandleSingleCommand foo" stuff littered around my story, I created a new function "UseAlias" which takes a single parameter "object" and then calls "HandleSingleCommand ("use " + object.name)"
I'm getting "Error running script: Error adding key 'push' to dictionary: An item with the same key has already been added." now though because there is already a "push/pull" verb in the Core...still trying to figure out a way around that.
Otherwise, mostly set. Thank you both for the help!
Edit: With some fiddling, I was able to get that error to go away. I think I had to Copy the Core's "push" verb to my project and then delete it, and then change the attribute of my "push" to...something else, i.e. "pushButton".
The Pixie
30 Nov 2015, 07:24A far better way is to add a verb, and have the verb call the USE script.
On you button object, go to the Verbs tab, and click Add. Type in "push". Select "Ruin a script" at the bottom. Then Click on "Add new script" and from the list, pick "Run an object's script attribute". Set it up like this:
Run object [expression] this script attribute [name] [use]
Now if you change what the USE action is, the PUSH action will automatically be changed too, because it just uses the the same code.
On you button object, go to the Verbs tab, and click Add. Type in "push". Select "Ruin a script" at the bottom. Then Click on "Add new script" and from the list, pick "Run an object's script attribute". Set it up like this:
Run object [expression] this script attribute [name] [use]
Now if you change what the USE action is, the PUSH action will automatically be changed too, because it just uses the the same code.