Changing clones.[SOLVED]

Io
25 Feb 2018, 21:58

So lets say I have a room called Crusher, with a metal wall that comes down and crushes things when a switch is flipped. And let's say I want to use it to crush eggs. But I want it to be able to crush multiple eggs at a time. So instead of making 10 different egg objects, I create 1 egg object and stick it in a DebugRoom room. Then I make 10 clones of the egg and move them to the Crusher room. I give it the attribute Crushed and set to false.

So the input is given and the Crusher room 'crushes'. How do I make it so that all the clones of the egg - and only the egg - in the room have Crushed set to true?


K.V.
25 Feb 2018, 22:06

Are you using the most recent version of Quest? (5.7.2)


Io
25 Feb 2018, 22:14

No, I'm using 5.5. Is there something in 5.7.2 that could do this?


K.V.
25 Feb 2018, 22:15

Never mind my last question. It's not relevant.

EDIT: I don't know if this will work in 5.5, but, if not, it would be because a function was missing, and that should throw an error when loading the game in the player.

To create 10 clones of the egg:

i = 10
while (i>0) {
  newClone = CloneObjectAndMove(egg,Crusher)
  newClone.cloned_egg = true
  newClone.Crushed = false
  i = i - 1
}

To crush:

foreach (obj, FilterByAttribute(GetDirectChildren(Crusher),"cloned_egg",true)) {
  obj.Crushed = true
}

Io
25 Feb 2018, 22:22

I didn't have trouble making the clones, I know that well enough. I just wasn't sure how to tell the crusher 'No, look at the clones, not the parent!' Let me go test it out.


Io
25 Feb 2018, 22:28

Cloning works. Smashing does not. Doesn't throw an error when loading, but when I told it to crush the eggs it gave me one instance of this:

Error running script: Error compiling expression 'FilterByAttribute(GetDirectChildren(Crusher),"cloned_egg",true)': FunctionCallElement: Could find not function 'FilterByAttribute(QuestList`1, String, Boolean)'


K.V.
25 Feb 2018, 22:35

When creating the clones, I'm adding the attribute cloned_egg and setting it to true on each clone in the creation script, then only changing Crushed to true on objects in the Crusher with cloned_egg set to true.

Check out my clone creation script one more time, and you'll see the line that does that.


I asked which version of Quest you had because clones automatically have the prototype object attribute as of 5.7.2.

If you clone an egg in 5.7.2, the clone will be set up with Object: egg as the value of its prototype attribute.

...but, if you just add the cloned_egg attribute and set it to true while creating the clones, you can check for that the same way.

In 5.7.2, you could clone the egg with no extra code, and the script to crush would be:

foreach (obj, FilterByAttribute(GetDirectChildren(Crusher),"prototype",egg)) {
  obj.Crushed = true
}

Io
25 Feb 2018, 22:39

No no, I did that too. I added the attribute crushed_egg as a boolean, set it to false for the parent, and had the cloner set it to true for the clones. It seems to regard "cloned_egg" as just some unrecognizable string, rather than something to check for. removing the quotation marks results in:

Error running script: Error compiling expression 'FilterByAttribute(GetDirectChildren(Crusher),cloned_egg,true)': Unknown object or variable 'cloned_egg'

But I did not know it does that in 5.7.2! Definitely updating now, that sounds immeasurably useful. Will see if your suggested 5.7.2 code will work.


hegemonkhan
25 Feb 2018, 22:40

the 'FilterByAttribute' Script/Function is a new addition by Pixie in his newer versions, so v550 (same as I'm still using, I think, lol) doesn't have this Script/Function

you can do this instead:

foreach (obj, GetDirectChildren(Crusher)) {
  if (GetBoolean (obj, "cloned_egg")) {
    obj.Crushed = true
  }
}

Io
25 Feb 2018, 22:43

Update: K.V., your code works now that I have 5.7.2, thanks. This opens up a whole new world for me!

hegemonkhan, thank you as well. I didn't even know GetDirectChildren(Something) existed. Time to nest EVERYTHING.


K.V.
25 Feb 2018, 22:43

Error running script: Error compiling expression 'FilterByAttribute(GetDirectChildren(Crusher),cloned_egg,true)': Unknown object or variable 'cloned_egg'

Do you have "cloned_egg" or cloned_egg?

It should be in quotation marks in this:

foreach (obj, FilterByAttribute(GetDirectChildren(Crusher),"cloned_egg",true)) {

hegemonkhan
25 Feb 2018, 22:45

here are most of the built-in Scripts/Functions:

http://docs.textadventures.co.uk/quest/scripts/

http://docs.textadventures.co.uk/quest/functions/ (categorical order)
http://docs.textadventures.co.uk/quest/functions/index_allfunctions.html (alphabetical order)


Io
25 Feb 2018, 22:47

K.V. it works now, but I tried it with both. With quotation marks, I got the former error. Without, I got the latter.

hegemonkhan excuse me while I bookmark those.


hegemonkhan
25 Feb 2018, 22:53

here's some more useful links (you can try learning/navigating the doc site yourself, but some things are a bit hidden: hard to find or to know about):

http://docs.textadventures.co.uk/quest/upgrade_notes.html (not too relevant anymore... as few are using the older older versions, lol. This was very useful though in the past, lol)

http://docs.textadventures.co.uk/quest/asl_requirements.html

http://docs.textadventures.co.uk/quest/aslx.html

http://docs.textadventures.co.uk/quest/#Howto (some more guides)

http://docs.textadventures.co.uk/quest/elements/

http://docs.textadventures.co.uk/quest/types/

this is very useful (all/most of the built-in Attributes for Objects!):

http://docs.textadventures.co.uk/quest/elements/object.html

ask if you need help with anything!


Io
25 Feb 2018, 22:54

Oh my GOD there's an 'Objects dropped here go to' this changes everything.


hegemonkhan
25 Feb 2018, 23:12

(filler for getting my edited post, updated/posted)
(again, filler for getting my edited post, updated/posted)
(again, filler for getting my edited post, updated/posted)
(again, filler for getting my edited post, updated/posted)
(again, filler for getting my edited post, updated/posted)


explaining the double quotes vs no double quotes (using KV's example scripting):


anything in double quotes IS a STRING DATA/ATTRIBUTE/VALUE TYPE !!!

'NAME_OF_ATTRIBUTE' are String DATA TYPES, so they must have double quotes when used as a Parameter's Argument/input Value

'NAME_OF_OBJECT.NAME_OF_ATTRIBUTE' are ATTRIBUTES, and thus NOT String Data Types, so you do NOT (you NEVER) put them in double quotes!

'NAME_OF_OBJECT' (excluding the special/reversed words such as 'true/True/false/False' which are recognized as Boolean DATA TYPES/VALUES) are Object (reference/pointer) Data Types, so you do NOT put them in double quotes, as they're not String Data Types

'true/True/false/Fale' are Boolean DATA/VALUE Types, so they're not Strings, but also not Objects, though they still do NOT have double quotes (quest is programmed to understand these as special/reserved words/values, as belonging to Booleans, and will not be recognized as Objects/object_references_pointers/names_of_objects


foreach (obj, FilterByAttribute(GetDirectChildren(Crusher), "cloned_egg", true)) {

here's it in HK's GENERAL SYNTAX (lol):

foreach (a_local_temporary_custom_(aka: self created/named)_Variable_as_NAME_OF_Variable, FilterByAttribute (GetDirectChildren (NAME_OF_OBJECT), "NAME_OF_ATTRIBUTE", VALUE_OF_ATTRIBUTE)) {

it might be easier to understand it better if we break it up into multiple code lines, instead of combined (nested) as one code line:

// this puts all direct child/sub Objects of the parent 'NAME_OF_OBJECT' into an Objectlist Variable and RETURNS IT (an Objectlist Variable), which is being stored in my: example_objectlist_1_variable:

example_objectlist_1_variable = GetDirectChildren (NAME_OF_OBJECT)

// does does the same as the above, except it is taking the Objectlist Variable of the direct child/sub Objects, and iterating through them, finding any of those direct child/sub Objects, that have the 'NAME_OF_ATTRIBUTE = VALUE_OF_ATTRIBUTE' Attribute (and its specified Value), and puts them into another Objectlist Variable and RETURNS IT (an Objectlist Variable), which is being stored in my: example_objectlist_2_variable:

example_objectlist_2_variable = FilterByAttribute (example_objectlist_1_variable, "NAME_OF_ATTRIBUTE", VALUE_OF_ATTRIBUTE)

// now we again iterate through all/every/each (forEACH, lol) the Objects from 'example_objectlist_2_variable), and do (the 'foreach' Script/Function does it automatically, behind the scenes, for you) the nested scripting for each of them:

foreach (example_item_object_variable, example_objectlist_2_variable) {
  // whatever scripting (using whatever you named the local-temporary Variable as, instead of my naming of 'example_item_object_variable' local-temporary Variable, lol)
}