Using put command for surface containers to trigger scripts
Talon
21 Jun 2017, 20:23I have a magical trophy that I intend to have show the history of various items when they are put inside the bowl at the top of it, a player brings an item, puts it in, gets the story, then can remove it and put in another.
My aim is to have a script fire(though currently just a list of strings) fire when certain items are put into the trophy, so if you put object A in it will tell you the story behind it, If you put B in you'd get something else..
Right now I'm thinking of doing it with a kind of change script on the trophy that checks what each item is with a If-else sort of script, would have a maximum of one item in it to keep things from conflicting
Would modifying the Put command to first check for a object attribute be better?
hegemonkhan
22 Jun 2017, 00:51you can either:
- "physically" have Objects within your 'TROPHY/BOWL' Object
or - "logically" have Object references/pointers via within an Objectlist Attribute of your 'TROPHY/BOWL' Object
http://docs.textadventures.co.uk/quest/using_lists.html
http://docs.textadventures.co.uk/quest/using_dictionaries.html
// using the 'game' Game Settings Object as an example, but can add Dictionary Attributes to any Object:
<game name="example_game">
<attr name="example_scriptdictionary_attribute" type="scriptdictionary">
<item key="NAME_OF_OBJECT_1">
msg ("NAME_OF_OBJECT_1's history")
</item>
<item key="NAME_OF_OBJECT_1">
msg ("NAME_OF_OBJECT_2's history")
</item>
</attr>
</game>
// --------------------------
// "physically"
// NAME_OF_OBJECT.parent = TROPHY/BOWL // MoveObject (NAME_OF_OBJECT, TROPHY/BOWL)
if (Contains (TROPHY/BOWL, NAME_OF_OBJECT)) {
msg (NAME_OF_OBJECT.alias + " is in the TROPHY/BOWL")
msg ("NAME_OF_OBJECT's history")
}
// and/or:
foreach (object_variable, ScopeVisibleNotHeldForRoom (TROPHY/BOWL)) { // hopefully this works for an Object, otherwise, you'll have to make your 'TROPHY/BOWL' Object be a Room Object... meh... or we'd need to do additional code work...
// optionally: use 'if' block to check for specific items only: if (object_variable.name = "NAME_OF_OBJECT_X", (and have the 'invoke' line below, nested within it), otherwise, all items will be done:
invoke (ScriptDictionaryItem (game.example_scriptdictionary_attribute, object_variable.name))
}
// ------------------------------
// "logically":
// TROPHY/BOWL.example_objectlist_attribute = NewObjectList ()
// list add (TROPHY/BOWL.example_objectlist_attribute, NAME_OF_OBJECT)
if (ListContains (TROPHY/BOWL.example_objectlist_attribute, NAME_OF_OBJECT)) {
msg (NAME_OF_OBJECT.alias + " is in the TROPHY/BOWL")
msg ("NAME_OF_OBJECT's history")
}
// and/or:
foreach (object_variable, TROPHY/BOWL.example_objectlist_attribute) {
// optionally: use 'if' block to check for specific items only: if (object_variable.name = "NAME_OF_OBJECT_X", (and have the 'invoke' line below, nested within it), otherwise, all items will be done:
invoke (ScriptDictionaryItem (game.example_scriptdictionary_attribute, object_variable.name))
}
where/how/when (as Verbs: such as within the over-ridden/copied-modified built-in 'put' Verb, Commands, Functions, etc) you use these scripting, you can decide that, and if you need help, ask/let us know, and we'll help you with whatever you want to do.
XanMag
22 Jun 2017, 04:53How many items are we talking about here?
Talon
25 Jun 2017, 04:51Definitely feels better to have the items physically within the bowl, will take a look through the text you've provided, have never dabbled with dictionaries thus far, mostly using tricks for lists and so on . Going to try to work on it in a couple days, minds utterly blitzed from this last week here.
Thinking in the range of a dozen or so various amulets and such
The Pixie
25 Jun 2017, 07:48Does the script need to fire whern the object is put in the bowl? Sounds like it is only needs when the player examines the bowl, which would be much easier - you just need to add a script for that, and have that check what is in the bowl.
Talon
26 Jun 2017, 02:24Thats a pretty good idea, see no problem logical(in game logic not scripting logic) of having the information portrayed when looking at the bowl. So would probably do a long if/else script that returns whatever the proper string would be. Having just one item being place able would keep things from interfering with eachother right?
The Pixie
26 Jun 2017, 07:10So would probably do a long if/else script that returns whatever the proper string would be.
Or give each item an attribute, "info", and put the text there. When the player looks at the bowl, check if there is an item in it, then check if the item has that attribute. If it does, display the attribute.
All the data for each item is then kept with the item, and if you add a new one, you just set that up, without messing with the bowl at all.
Having just one item being place able would keep things from interfering with eachother right?
Yes.