Adding object(x) to list

Hi. Is there a way of adding any item to a list. I want to set up a function whereby instead of countless
If got(flour) add flour to list1, I can use instead;
If got(x) add (x) to list1
If got(x) remove (x) from list2
Hope anyone can help. Thanks


I think you just have to specify what "x" is first, for example...

x = CloneObject (cloaknhood)
MoveObjectHere (x)

But I'm not sure if this helps you or not. @_@

Anonynn.


Do you mean like this???
list add (player.N1, N)

This adds "N" to the end of the list player.N1
IE:
N=22
player.N1 = Split(" 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20", ",")
list add (player.N1, N)
so that now:
player.N1 = Split(" 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,22", ",")
And:
N=5
list remove (player.N1, N)
player.N1 = Split(" 0, 1, 2, 3, 4, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,22", ",")


here, a guide on using lists and dictionaries:

http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk

other codings of using lists/dictionaries:

http://textadventures.co.uk/forum/samples/topic/5138/explore-and-travel-code-sample-by-hk
http://textadventures.co.uk/forum/samples/topic/4988/character-creation-crude-code-and-sample-game

a guide on using attributes and the 'if' script:

http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk

ask if you need help on anything


Do you mean, add x, where x is a variable, instead of a specific item? Yes, this will work:

x = flour
If got(x) add (x) to list1
If got(x) remove (x) from list2

The actual code would look like this:

x = flour
if (Got(x)) {
  list add (list1, x)
}
if (Got(x)) {
  list remove (list2, x)
}

If you could give more details, perhaps the context, we might be able to help more.


okay, here goes. I have an object called bowl, with an attribute string called ingredients of which there are about six items.

Rather than a condition script that says:
If object bowl contains object eggs and object bowl contains flour and object bowl contains sugar etc...Then ... do something

Is there a way of running a verb mix to do the following:
If object bowl contains bowl.ingredients Then... do something


If the bowl can only contains the ingredients and can only contain one of each, then you can check the number of item:

if (ListCount(GetDirectChildren(bowl)) = 6) {

Otherwise you could iterate through a string, but it is dubious if there is any benefit. I would check if each in turn is missing:

if (not Contains(bowl, sugar)) {
  msg("You need sugar in there.")
}
else if (not Contains(bowl, flour)) {
  msg("You need flour in there.")
}
etc.

Thanks Pixie, I think that's the route I want to take. How can I make the bowl only accept those ingredients, so I'm not counting a rogue item like 'dill' as part of the six, or how can I iterate through the string.


Like this?

put flour in bowl
You add the flour.
put sugar in bowl
You add the flour.
put dill in bowl
You don't want to do that, it would mess up the cake!

check each item as it is added.
You could have a list for different things to make.

make cake
(the program looks up the ingredients for a cake...)
player.make_cake=split("flour, sugar, ... ", ",")
To make the cake, you will need: (list of items)
Basically, just prevent the player from putting the dill in the bowl to start with...
Or, let them do it, but tell them after it is baked that it did not turn out right...


Hi, I really thought I was on to something here. I've set up the ingredients as a string list in the bowl object. I've added a verb 'mix' to the bowl object, then I thought, what about ListExclude, exclude the bowl.ingredients list from the GetDirectChildren(bowl) list. But no doesn't work.
I've copied in what I've done below. Hope someone can tell me if I'm on to the right track, point out where I've gone wrong, or tell me Quest doesn't work that way.

<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Test - Multiple Objects">
    <gameid>e1ee6bb2-6774-4a26-a79d-bfc48f17d950</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="bowl">
      <inherit name="editor_object" />
      <inherit name="surface" />
      <feature_container />
      <contentsprefix>in which there is</contentsprefix>
      <take />
      <mix type="script">
        result = ListExclude ( bowl.ingredients , GetDirectChildren ( bowl ) )
        if (result=0) {
          msg ("You have all the ingredients to make a cake.")
        }
        else {
          msg ("You still need more ingredients")
        }
      </mix>
      <ingredients type="stringlist">
        <value>sugar</value>
        <value>flour</value>
        <value>eggs</value>
        <value>butter</value>
      </ingredients>
    </object>
    <object name="sugar">
      <inherit name="editor_object" />
      <take />
    </object>
    <object name="flour">
      <inherit name="editor_object" />
      <take />
    </object>
    <object name="eggs">
      <inherit name="editor_object" />
      <take />
    </object>
    <object name="butter">
      <inherit name="editor_object" />
      <take />
    </object>
  </object>
  <verb>
    <property>mix</property>
    <pattern>mix</pattern>
    <defaultexpression>"You can't mix " + object.article + "."</defaultexpression>
  </verb>
</asl>

Hope you can help. Thanks


here's about using 'ListExclude' and 'ListCount', below:

http://docs.textadventures.co.uk/quest/functions/listexclude.html
http://docs.textadventures.co.uk/quest/functions/listcount.html


first, you're using a STRING List Attribute:

<ingredients type="stringlist">
  <value>sugar</value>
  <value>flour</value>
  <value>eggs</value>
  <value>butter</value>
</ingredients>

this needs to be an Object List Attribute (or you'd need to use 'GetObject (NAME_OF_STRING)' with your String List Attribute's items/Values):

<ingredients type="objectlist">
  <value>sugar</value>
  <value>flour</value>
  <value>eggs</value>
  <value>butter</value>
</ingredients>

next, let's looks at what you're doing with 'ListExclude', below:

  1. (we're pretending that we've already fixed the issue of 'ingredients' being a StringList Attribute, fixed/changed correctly to an ObjectList Attribute)
  2. bowl.ingredients: sugar, flour, eggs, butter (4 items/Values: 4 Object references/pointers)
  3. make a copy of 'bowl.ingredients', thus: bowl.ingredients_copy: sugar, flour, eggs, butter (4 items/Values: (4 items/Values: 4 Object references/pointers)
  4. for ALL/EACH/EVERY Object(s) directly inside of your 'bowl' Object (NOT objects inside of Objects that are inside of the 'bowl' Object), check if they match up with the items/Values (Object references/pointers) in your 'bowl.ingredients_copy' ObjectList Attribute, if they do, then REMOVE that item/Value (Object reference/pointer) from your 'bowl.ingredients_copy' ObjectList Attribute.
  5. your 'if (result = 0)' isn't how the correct scripting is done. It needs to be like this:
if (ListCount (result) = 0) {
  msg ("You have all the ingredients to make a cake.")
} else {
  msg ("You still need more ingredients")
}
  1. "lastly" (actually this happens BEFORE #4 above), you're storing your copy objectlist into the 'result' Variable VARIABLE

so....

You almost had it right! (Good Job!)

just change your 'ingredients' to being of Attribute/Data Type: 'objectlist', and change your 'if (result = 0) { /* scripting / }' to being: if (ListCount (result) = 0) { / scripting */ }


do note that the design you're using, you got to have/move/put/set your 'sugar', 'flour', 'eggs', and 'butter' Objects into your 'bowl' Object, and with the design/code that it is now, you have to have ALL 4 Objects (sugar, flour, eggs, butters) in your 'bowl' Object at the same time, as when you execute your 'mix'. If you don't like this, I can help with fixing up the code for handling this issue.

(The issue is that you're checking the temporary copy objectlist, which is destroyed when its parent scripting is done, and as well as that you're removing the items from it: the copy objectlist, as well, which it is good that you're not removing the items from your control/original objectlist, but maybe you might want to store the remaining items in a permanent objectlist and check it instead, as this would be how we fix the issue of currently needing all 4 items:Objects to be in the 'bowl' object at the same time, due to currently using the copy temporary objectlist)


That is (almost) a neat way of doing it. Your ingredients attribute is a list of strings, but the contents of the bowl is a list of objects. Your list exclude will always fail to actually remove anything from the list as there are no matches.

You cannot do object lists through the Attributes tab, you would have to set it up in code, in the start script of the game object.

bowl.ingredients = NewObjectList()
list add (bowl.ingredients, sugar)
list add (bowl.ingredients, flour)
list add (bowl.ingredients, eggs)
list add (bowl.ingredients, butter)

Thanks for the help and advice. I'll have a go and see if I can sort it out. Still relatively new to Quest. Only came across it at the start of the year. Not done much programming since the mid 80's on the Dragon32 (hence the username) and the Commodore64 using GAC (Graphic Adventure Creator), both computers I still own.
If I have any trouble, I know I can ask for help.
Cheers.


Log in to post a reply.

Support

Forums