Different objects in a container raising different flags
XanMag
23 Jul 2016, 14:45I've spilled a can of beans here and I'm not sure how to clean it up...
If you helped with a previous post, forgive this brief summation:
I have a metal barrel container. For the barrel to be useful, I need the proper objects placed in this container. They are:
moss2, planks2, and glass crescent. (the final object can only be placed in/on the container at the very end so I'm not concerned with that. The player can however place moss1 and planks1 in the container as well.
Here are the container possibilities and corresponding flags on the metal barrel:
- moss2, planks2(ready)
- moss1, planks2 (lacksdrymoss)
- moss2, planks1 (lacksoil)
- moss1, planks1 (farfromready)
- Any combination other than mentioned above - one of the three are lacking = no flag set.
GOAL 1: I think the best way to do this is to only allow the glass crescent to be added to the metal barrel IF some version of moss and planks are already in the metal barrel.
So, 1st question... Is the easiest way to achieve goal 1 to place an 'If' statement in the 'put glass crescent in barrel' command to check and see if the barrel contains two items (know that it is set up so that ONLY moss1, moss2, planks1, and planks2 can be placed in the barrel)?
2nd question: What is the easiest way to script checking if there are two items in the metal barrel? I was thinking that in the 'put crescent in barrel' command, I use the AND option to check if metal barrel contains moss2 AND planks2 then ..., else if moss1 AND planks2, then ..., etc, Else then print message hinting to the player that the barrel is not ready for the glass crescent.
3rd question: I think I also need to constantly check the barrel contents to raise the appropriate flag, right? Example, If two items are in the barrel, say moss1 and planks2, and the player decides to 'put crescent in barrel', nothing happens in the barrel because it is not ready (lacksdrymoss). In this script, the player returns the crescent to their inventory, but upon doing so, there is a hint indicating that there is something not quite right about the moss. The player should then know to remove moss and take some action on it. So... where would I run this constant check on the barrel? Do I put it in the game start up script? If metal barrel contains moss2 AND planks2, then set flag ready? Else If moss1 AND planks1 then set flag farfromready, etc?
Sorry for the long-winded explanation, but it drives me nutty when I realize after four hours of tinkering that there was a much easier way to do it! Thanks!
bergedorfcacher
23 Jul 2016, 19:13Hmm, are you sure you need flags? That would make sense if you need to check them at several places. If however the only place you need this for is when the user lights the moss up, you might as well only check the 'readyness' at that time.
hegemonkhan
23 Jul 2016, 19:19here I go again, probably another fail post, but I like trying to help regardless (as well as it being more code practice for me), so if this post is of no use, wait for Pixie's, Jay's, and/or whoever else's, of course. Also, my method probably won't be as efficient as theirs, as I'm still learning to code better.
personally, for me, you don't need any Booleans (or 'flags' as you call them), as they're unneccessary/extra Attributes. Your conditionals (if new_ingredient_object = or not = blah_object and if container_object contains previous/old_ingredient_object/s, move new_ingredient_object into container_object), will handle it all for you, so you don't need any of Booleans stating the same thing/states (ie: moss1_and_moss2_are_contained_boolean_attribute = true). Though, for using the completed container with other scripts (aka: having your final/last glass cresent ingredient object inside of the container object), you can have a Boolean for this if you want, ie: completed_container_object_boolean = true.
the code can probably be made more efficient with how it's logically ordered... and/or you could also use Lists too, but there were only 5 ingredient/mixing objects, so don't really need lists (not sure if using/checking lists would be more efficient than just the checking of the 'Contains' of the 5 various mixing ingredient/item Objects that I did in the code below, meh)
lastly, I did NOT handle for the use of clones... as it would take a bit more code work to add in the needed scripting for the handling of the clones (checking of/for their names via 'StartsWith (CLONE) = OBJECTS_NAME') and etc whatever other possibly needed scripting.
HK edit:
optionally, if you want/need, I forgot to put in what would be an initial check of the 'mixing_completed_boolean_attribute' (flag/indicator use of in this case, a) Boolean Attribute, to prevent you from being able to do the mixing again after you've completed the mixing... maybe you want this or maybe you don't. Let me know if you want to prevent from being able to do the mixing again after completion of the mixing.
<object name="barrel_1">
<attr name="parent" type="object">room_1</attr>
<attr name="alias" type="string">metal barrel</attr>
<attr name="mixing_completed_boolean_attribute" type="boolean">false</attr>
<attr name="take" type="boolean">true</attr> // quest shortens this (to the left) syntax to: <take />
<attr name="drop" type="boolean">true</attr> // quest shortens this (to the left) syntax to: <drop />
<attr name="displayverbs" type="simplestringlist">look;take;mix</attr>
<attr name="inventoryverbs" type="simplestringlist">look;drop;mix</attr>
<attr name="mix" type="script">
barrel_1_mixing_function
</attr>
</object>
<object name="moss_1">
<attr name="parent" type="object">room_1</attr>
<attr name="alias" type="object">wet moss</attr>
<attr name="take" type="boolean">true</attr> // quest shortens this (to the left) syntax to: <take />
<attr name="drop" type="boolean">true</attr> // quest shortens this (to the left) syntax to: <drop />
<attr name="displayverbs" type="simplestringlist">look;take</attr>
<attr name="inventoryverbs" type="simplestringlist">look;drop</attr>
</object>
<object name="moss_2">
<attr name="parent" type="object">room_1</attr>
<attr name="alias" type="string">dry moss</attr>
<attr name="take" type="boolean">true</attr> // quest shortens this (to the left) syntax to: <take />
<attr name="drop" type="boolean">true</attr> // quest shortens this (to the left) syntax to: <drop />
<attr name="displayverbs" type="simplestringlist">look;take</attr>
<attr name="inventoryverbs" type="simplestringlist">look;drop</attr>
</object>
<object name="planks_1">
<attr name="parent" type="object">room_1</attr>
<attr name="alias" type="string">xxx</attr>
<attr name="take" type="boolean">true</attr> // quest shortens this (to the left) syntax to: <take />
<attr name="drop" type="boolean">true</attr> // quest shortens this (to the left) syntax to: <drop />
<attr name="displayverbs" type="simplestringlist">look;take</attr>
<attr name="inventoryverbs" type="simplestringlist">look;drop</attr>
</object>
<object name="planks_2">
<attr name="parent" type="object">room_1</attr>
<attr name="alias" type="string">soil</attr>
<attr name="take" type="boolean">true</attr> // quest shortens this (to the left) syntax to: <take />
<attr name="drop" type="boolean">true</attr> // quest shortens this (to the left) syntax to: <drop />
<attr name="displayverbs" type="simplestringlist">look;take</attr>
<attr name="inventoryverbs" type="simplestringlist">look;drop</attr>
</object>
<object name="cresent_1">
<attr name="parent" type="object">room_1</attr>
<attr name="alias" type="string">glass cresent</attr>
<attr name="take" type="boolean">true</attr> // quest shortens this (to the left) syntax to: <take />
<attr name="drop" type="boolean">true</attr> // quest shortens this (to the left) syntax to: <drop />
<attr name="displayverbs" type="simplestringlist">look;take</attr>
<attr name="inventoryverbs" type="simplestringlist">look;drop</attr>
</object>
<object name="player">
<attr name="parent" type="object">room_1</attr>
</object>
<object name="room_1">
<attr name="alias" type="string">room</attr>
</object>
<verb>
<property>mix</property>
<pattern>mix</property>
<defaultexpression>You can't mix that!</defaultexpression>
</verb>
<function name="barrel_1_mixing_function">
if (Contains (barrel_1, null)) {
if (Contains (player, moss_1)) {
moss_1.parent = barrel_1 // or if you like better: MoveObject (moss_1, barrel_1)
} else if (Contains (player, planks_1)) {
planks_1.parent = barrel_1 // or if you like better: MoveObject (planks_1, barrel_1)
} else if (Contains (player, moss_1) and Contains (player, planks_1)) {
moss_1.parent = barrel_1 // or if you like better: MoveObject (moss_1, barrel_1)
planks_1.parent = barrel_1 // or if you like better: MoveObject (planks_1, barrel_1)
} else if (Contains (player, moss_2) or Contains (player, planks_2)) {
msg ("Sorry, but you first need to add the 'dry moss (moss_1)' and 'xxx (planks_1)' into the 'barrel_1', before you can add the 'wet moss (moss_2)' or 'soil (planks_2)' into the 'barrel_1'.")
} else if (Contains (player, cresent_1)) {
msg ("Sorry, but you first need to add the 'wet moss (moss_2)' and 'soil (planks_2)' into the 'barrel_1', before you can add the 'glass cresent (cresent_1)' into the 'barrel_1'.")
} else {
msg ("You can only initially mix 'dry moss (moss_1)' and 'xxx (planks_1)' into the 'barrel_1'.")
}
} else if (not Contains (barrel_1, moss_1)) {
if (Contains (player, moss_1)) {
moss_1.parent = barrel_1 // or if you like better: MoveObject (moss_1, barrel_1)
} else {
msg ("You need to mix 'dry moss (moss_1)' into the 'barrel_1' before you can mix the next set of ingredients, 'wet moss (moss_2)' and 'soil (planks_2)', into the 'barrel_1'.")
}
} else if (not Contains (barrel_1, planks_1)) {
if (Contains (player, planks_1)) {
planks_1.parent = barrel_1 // or if you like better: MoveObject (planks_1, barrel_1)
} else {
msg ("You need to mix 'xxx (planks_1)' into the 'barrel_1' before you can mix the next set of ingredients, 'wet moss (moss_2)' and 'soil (planks_2)', into the 'barrel_1'.")
}
} else if (Contains (barrel_1, moss_1) and Contains (barrel_1, planks_1)) { // actually, this code line can just be an 'else', you don't need the 'if' contional part of it, so it could just be this: } else {
if (not Contains (barrel_1, moss_2)) {
if (Contains (player, moss_2)) {
moss_2.parent = barrel_1 // or if you like better: MoveObject (moss_2, barrel_1)
} else {
msg ("You need to mix the 'wet moss (moss_2)' into the 'barrel_1' before you can mix the last ingredient stage, 'glass cresent (cresent_1)', into the 'barrel_1'.")
}
} else if (not Contains (barrel_1, planks_2)) {
if (Contains (player, planks_2)) {
planks_2.parent = barrel_1 // or if you like better: MoveObject (planks_2, barrel_1)
} else {
msg ("You need to mix the 'soil (planks_2)' into the 'barrel_1' before you can mix the last ingredient stage, 'glass cresent (cresent_1)', into the 'barrel_1'.")
}
} else if (Contains (barrel_1, moss_2) and Contains (barrel, planks2)) { // actually, this code line can just be an 'else', you don't need the 'if' contional part of it, so it could just be this: } else {
if (Contains (player, cresent_1)) {
cresent_1.parent = barrel_1 // or if you like better: MoveObject (cresent_1, barrel_1)
barrel.mixing_completed_boolean_attribute = true
msg ("You've completed the mixing process for the 'barrel_1'.")
} else {
msg ("You're missing the last mixing ingredient, 'glass cresent (cresent_1)', needed for the last stage of the mixing process with the using of the 'barrel_1'.")
}
}
}
</function>
XanMag
23 Jul 2016, 19:27Yes, I think I need flags. The puzzle solution essentially is:
Thanks.
hegemonkhan
23 Jul 2016, 19:31ah, yes, that would be a good reason/use of (additional/sub) flags. You can add in those (additional/sub) flags (for the various combinations of what you currently have in my use of 'barrel_1') easily into my code.
bergedorfcacher
23 Jul 2016, 19:38I guess it's a matter of personal taste. You certainly need to compute if things are ready (and if not why not) at some point. You could do that computation always when something relevant changes and save the results in flags that you can use for finding out what hints to give. Or you could just do the computation on the fly when you need to know what hint (if any) to give. I'd prefer the on thy fly method, because I'd be worried to miss something in the 'when something relevant changes' part.
hegemonkhan seems to have thoughts similar to mine. I haven't looked at his code in detail, but I think it is an example for the 'on the fly' method.
But again: it certainly can be done with flags too.
hegemonkhan
23 Jul 2016, 19:54@bergedorfcacher:
my code allows for easily putting in the needed 'sub' (flags/indicators as in this case) Boolean Attributes, but it doesn't have them in the code now.
most of my code is just the handling of all the different conditions/combinations of the 'mixing' effect/Verb itself and/or the prompting of the user of what's going on with the mixing effect/Verb (why and/or if something succeeds and/or fails).
P.S.
@XanMag:
I think I mixed (messed) up (lol, I'm using 'mixed' too much, haha. sorry bad pun usage) the 'moss_2' as 'wet moss (whereas I think you want it to be 'dry moss') and the 'moss_1' as 'dry moss' (whereas I think you want it to be 'wet moss'. Also, I've no idea what you're 'planks_1' is suppose to be, lol. I don't know botany/biology that well, so no idea what this 'plank' stuff is... (I know of a 'Planck's constant' and 'Plankton organisms ~ what baleen/most whales eat' --- can't spell, meh)
XanMag
23 Jul 2016, 20:22Ha. A plank is just like a 2x4.
hegemonkhan
23 Jul 2016, 20:41oh... haha... a wooden plank / a plank of wood.... HK always over thinks stuff, laughs! HAHA... HK is an idiot... but hey, this was a funny mistake on my part, hehe. A plank of wood... LAUGHS. I was trying to think of what some specific meaning of 'plank' was, completely forgetting that there's its general usage, a 2x4 or whatever: NxM (rectangle), a plank/rectangle of (whatever), etc etc etc, lol.
P.S.
does my code make sense XanMag? it's mainly just trying to account for all the different combination possibilities, and also prompting the user if needed about what's going on or not going on. You can adjust it as you want, it was just a sample example.
(Also, I've probably got some errors and/or logic errors in my code... if you find any, let me know and I'll fix it up)
XanMag
23 Jul 2016, 21:12Yep. I'll mess with it when I get home. Thanks!
hegemonkhan
24 Jul 2016, 09:16noticed a typo mistake in my code (in case you're using parts of it, aka copy+pasting, into your code):
on my last 'else if' line, the second 'barrel' is missing the '_1' on it. But, this is only a typo error for my ( / my code's) own naming/labeling of stuff
The Pixie
24 Jul 2016, 13:20So, 1st question... Is the easiest way to achieve goal 1 to place an 'If' statement in the 'put glass crescent in barrel' command to check and see if the barrel contains two items (know that it is set up so that ONLY moss1, moss2, planks1, and planks2 can be placed in the barrel)?
Yes.
2nd question: What is the easiest way to script checking if there are two items in the metal barrel? I was thinking that in the 'put crescent in barrel' command, I use the AND option to check if metal barrel contains moss2 AND planks2 then ..., else if moss1 AND planks2, then ..., etc, Else then print message hinting to the player that the barrel is not ready for the glass crescent.
I am with bergerdorfcacher, that you do not need flags. Check the parent attributes to see if something is present, something like this:
if (moss2.parent = barrel and planks2.parent = barrel) {
msg("That works fine.")
}
else if (moss1.parent = barrel and (planks2.parent = barrel or planks1.parent = barrel)) {
msg("The moss is too damp.")
}
else if (moss2.parent = barrel and planks1.parent = barrel) {
msg("There's no soil.")
}
else {
msg("That does not do anything.")
}
3rd question: I think I also need to constantly check the barrel contents to raise the appropriate flag, right? Example, If two items are in the barrel, say moss1 and planks2, and the player decides to 'put crescent in barrel', nothing happens in the barrel because it is not ready (lacksdrymoss). In this script, the player returns the crescent to their inventory, but upon doing so, there is a hint indicating that there is something not quite right about the moss. The player should then know to remove moss and take some action on it. So... where would I run this constant check on the barrel? Do I put it in the game start up script? If metal barrel contains moss2 AND planks2, then set flag ready? Else If moss1 AND planks1 then set flag farfromready, etc?
I see no reason to do this. Quest is already tracking what is in the barrel. he only time the player needs a message is when she tries to put the cresent in the barrel, which is covered above.