Changing one item in a list within a list? #1633
Unanswered
KVonGit
asked this question in
Creating games with Quest
Replies: 2 comments
-
|
I can't figure out how to do it with lists, but I seem to have it working with dictionaries: <function name="PICK_ONE_PLUS" parameters="dict" type="string">
FROB = DictionaryItem(dict, "lst")
L = ListCount(FROB)
CNT = DictionaryItem (dict, "cnt")
L = L - 1
RFROB = REST (FROB, CNT)
// because RFROB is just a vanilla list after using REST
lst = NewStringList()
foreach(s,RFROB){
list add(lst,s)
}
RFROB = lst
FROB = ListExclude(FROB,RFROB)
RND = RANDOM (L - CNT)
MSG = StringListItem (RFROB, RND)
RFROB = PUT (RFROB, RND, StringListItem (RFROB, 0))
RFROB = PUT (RFROB, 0, MSG)
// because RFROB is just a vanilla list after using PUT
lst = NewStringList()
foreach(s,FROB){
list add(lst,s)
}
foreach(s,RFROB){
list add(lst,s)
}
FROB = lst
CNT = CNT + 1
if (CNT = L + 1) {
CNT = 0
}
dictionary remove (dict, "cnt")
dictionary add (dict,"cnt",CNT)
dictionary remove (dict,"lst")
dictionary add (dict, "lst", FROB)
return (MSG)
</function>Instead of the first element in the list being the CNT, the dictionary has separate "cnt" and "list" entries. Seemed like I might as well make that part slightly easier while I was already hacking it up. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
[MANIACAL LAUGH] I seem to have it working with a list within an object's list attribute (like the example in the first post in this thread). =) <function name="PICK_ONE" parameters="FROB" type="string"><![CDATA[
L = ListCount(FROB) - 1
CNT = ToInt(StringListItem(FROB,0))
list remove (FROB, StringListItem(FROB,0))
RFROB = NewStringList()
tmplist = ListExclude(FROB,"")
for (i, 0, L-1) {
if (i >= CNT) {
list remove (FROB, StringListItem(tmplist,i))
list add (RFROB, StringListItem(tmplist,i))
}
}
RND = RANDOM(L-CNT) - 1
MSG = ListItem (RFROB, RND)
tmplist = ListExclude(RFROB,"")
RFROB = NewStringList()
list add (RFROB, MSG)
len = ListCount(tmplist)
i = len - 1
n = RND
for (item, 0, i) {
if (item = n) {
list add (tmplist, ListItem(tmplist,0))
}
else {
list add (RFROB, ListItem(tmplist,item))
}
}
tmpfrob = ListExclude(FROB,"")
CNT = CNT + 1
if (CNT = L) {
CNT = 0
}
foreach (s, tmpfrob) {
list remove (FROB, s)
}
list add (FROB, ToString (CNT))
foreach (s, tmpfrob) {
list add (FROB, s)
}
foreach (s, RFROB) {
list add (FROB, s)
}
return (MSG)
]]></function>Test script: msg ("=== MISS CATEGORY ===")
FROB = ListItem(GLOBAL.HERO_MELEE, 0)
REMARK(PICK_ONE(FROB),"thief","sword")
REMARK(PICK_ONE(FROB),"thief","sword")
REMARK(PICK_ONE(FROB),"thief","sword")
REMARK(PICK_ONE(FROB),"thief","sword")
REMARK(PICK_ONE(FROB),"thief","sword")
REMARK(PICK_ONE(FROB),"thief","sword")
msg ("cycled")
REMARK(PICK_ONE(FROB),"thief","sword")
msg ("=== HIT CATEGORY ===")
FROB = ListItem(GLOBAL.HERO_MELEE, 4)
REMARK(PICK_ONE(FROB),"thief","sword")
REMARK(PICK_ONE(FROB),"thief","sword")
REMARK(PICK_ONE(FROB),"thief","sword")
REMARK(PICK_ONE(FROB),"thief","sword")
msg ("cycled")
REMARK(PICK_ONE(FROB),"thief","sword")Output: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am porting the first table from the "FIGHTS" section: https://github.com/historicalsource/zork1/blob/97b7b3d68c075dd9af7da499c3e9690ada3471fd/1actions.zil#L3604-L3648
The table has seven "sub tables" (and each of those technically has its own table, but I'm using a string for that bit).
This script creates the list of lists perfectly fine, and I can properly navigate. The issue is the first item from each list...
Note that each "sub list" begins with "0". This is the
CNTvalue for these in ZIL. That is used by thePICK-ONEroutine. It's basicallyPickOneString, but it does not repeat any until it has shown them all. To do this, it increases theCNTvalue by one each time it runs on a table.So, this game has a routine that chooses a table from the main table, then calls PICK-ONE on that. Then REMARK replaces F-DEF and/or F-WEP with the proper object alias.
I've got everything copied over to Quest. My issue is updating the CNT value in my list, so the change sticks in
GLOBAL.HERO_MELEE.I think I'm going to have use separate list attributes, or maybe dictionaries, or something...
Beta Was this translation helpful? Give feedback.
All reactions