Lists/Dictionaries don't work in separate scripts?
Dreghen
19 Jun 2012, 21:06(This is going to be repetitive and I'm sorry)
I have seriously bare minimum experience, if it can even count as experience, so I've been running on the assumption that if I set a variable to be a dictionary or list, then it'll continue to be the dictionary/list until specifically set otherwise. So I've been assuming that the creation of a list would be carrying over.
But I've noticed that when I try to add values to a list or a dictionary in a separate scripts from the script that created it, then in-game they return this error
I'd have to create the list or dictionary in that script. But even then it doesn't get added to the menu in a different script.
And when I go do the action that creates the menu and adds items to it that do work, the item added in another string is not present.
I think that I'm understanding how to make a menu, because when I do it all in one script it works perfectly.
What I'm mainly trying to do right now is add dialogue options without having to set and unset and check for flags all over the place, which I can do but would really rather not. (Like I said, I'm inexperienced so I might be living in a fantasy land for thinking that's possible)
For example, I want to be able to speak to a character and have a menu of topics come up and I want to add topics based on what you do. Like if you pick up an object, you'd get the option to Talk About The Object in the menu.
What I've been trying that hasn't worked is that I create the dictionary/list (it really doesn't seem to matter which I try because the results have been the same both ways) in the start-up script or in an initial action's First Time. Then I add a different action and in the string of that action I use "dictionary add (menu, "key", string)" so that the new option would appear in the menu. (Which of course doesn't work)
Here's an example of the test game in which I've tried to work it out.
I figure the code should be enough since it's not actually a full game but if it'd be better for me to upload the game file I can.
Is there any way to get this to work/is this a bug/do I have alternative options (other than a lot of flagging and/or "If" functions)?
I have seriously bare minimum experience, if it can even count as experience, so I've been running on the assumption that if I set a variable to be a dictionary or list, then it'll continue to be the dictionary/list until specifically set otherwise. So I've been assuming that the creation of a list would be carrying over.
But I've noticed that when I try to add values to a list or a dictionary in a separate scripts from the script that created it, then in-game they return this error
Error running script: Unknown object or variable '[menu variable]'
I'd have to create the list or dictionary in that script. But even then it doesn't get added to the menu in a different script.
And when I go do the action that creates the menu and adds items to it that do work, the item added in another string is not present.
I think that I'm understanding how to make a menu, because when I do it all in one script it works perfectly.
What I'm mainly trying to do right now is add dialogue options without having to set and unset and check for flags all over the place, which I can do but would really rather not. (Like I said, I'm inexperienced so I might be living in a fantasy land for thinking that's possible)
For example, I want to be able to speak to a character and have a menu of topics come up and I want to add topics based on what you do. Like if you pick up an object, you'd get the option to Talk About The Object in the menu.
What I've been trying that hasn't worked is that I create the dictionary/list (it really doesn't seem to matter which I try because the results have been the same both ways) in the start-up script or in an initial action's First Time. Then I add a different action and in the string of that action I use "dictionary add (menu, "key", string)" so that the new option would appear in the menu. (Which of course doesn't work)
Here's an example of the test game in which I've tried to work it out.
I figure the code should be enough since it's not actually a full game but if it'd be better for me to upload the game file I can.
<!--Saved by Quest 5.2.4515.34846-->
<asl version="520">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Menu Test">
<gameid>56af0d25-73a7-41dc-8a6b-f26ac1944d49</gameid>
<version>1.0</version>
<start type="script">
menu = NewStringList()
</start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="defaultplayer" />
</object>
<object name="Test Object">
<inherit name="editor_object" />
<displayverbs>Look at; Take; Show Menu; Add</displayverbs>
<showmenu type="script">
msg ("Showing menu:")
show menu ("Menu: ", menu, true) {
if (result=food) {
}
}
</showmenu>
<add type="script">
msg ("Adding food to menu")
dictionary add (menu, "food", food)
</add>
</object>
</object>
<verb>
<property>showmenu</property>
<pattern>show menu</pattern>
<defaultexpression>"You can't show menu " + object.article + "."</defaultexpression>
</verb>
<verb>
<property>add</property>
<pattern>add</pattern>
<defaultexpression>"You can't add " + object.article + "."</defaultexpression>
</verb>
</asl>
Is there any way to get this to work/is this a bug/do I have alternative options (other than a lot of flagging and/or "If" functions)?

Pertex
20 Jun 2012, 06:38If you want to use such a dictionary/list outside your script, you must save itwithin an object. Instead of
Then you can call it all over the game like
Be careful! Don't mix list and dictionariy commands
Here is your working gamefile
menu = NewStringDictionary()
you could save it in the game object like thisgame.menu = NewStringDictionary()
Then you can call it all over the game like
show menu ("Menu: ", game.menu, true) {
Be careful! Don't mix list and dictionariy commands
Here is your working gamefile
Dreghen
20 Jun 2012, 20:07Thank you very much!
sgreig
20 Jun 2012, 22:49Aww, Pertex beat me to it. 
