If Not Question :)

Anonynn
05 Jan 2016, 03:59
So I had a logic question that I'm having trouble sorting through. I get the concept, just not how to implement it.

Basically, I have two different types of containers.
1. Ones that CAN hold water and items.
2. Ones that can ONLY hold items.

I have two water objects so far...
1. Fresh Water.
2. Dirty Water.

So my question is, how do I handle containers that cannot hold anything except water.

Here's a script of one item that cannot hold water.

if (Contains (small_sack,fresh_water)) {
msg ("<br/>You cannot store liquids in this small sack! <br/>")
RemoveObject (fresh_water)
}
else if (Contains (small_sack,dirty_water)) {
msg ("<br/>You cannot store liquids in this small sack! <br/>")
RemoveObject (dirty_water)
}

See it's easier to do it this way because I only have two water items. But what would be the logic for...

Removing any item that is NOT water? Since "Remove Item" applies to one item.

Thanks in advance!

XanMag
05 Jan 2016, 05:08
Can you use something like this here?

if (not obj =

I used it when dropping all inventory except two items. It seems like you could use something similar in your filling container message? Just a thought.

It was from this thread if you can pull any use out of it?

viewtopic.php?f=10&t=5699

HegemonKhan
05 Jan 2016, 05:34
To deal with multiple items, you need to use lists, as they allow you to iterate (cycle) through all of the items (via using 'foreach' Function) and act or don't act upon them depending on if they match or don't match your conditions (your 'if' scripts).

--------------------------

IMPORTANT NOTE:

when adding~putting Objects into an Objectlist Attribute (or when getting~creating an Objectlist containing Objects), those Objects are *NOT* physically moved into the Objectlist. Think of an Objectlist Attribute as like a PE class student roster (a piece of paper with the PE students names on it, NOT the actual physical students themselves on the paper roster, lol), which can be used to do actions upon those Objects, but the Objects themselves remain physically where-ever they are located at, despite their names being put into~onto the roster~Objectlist Attribute, (unless the action you're doing is a 'MoveObject' Function that moves an Object to inside of another Object, of course). An Object can NEVER physically be inside or put into an Objectlist.

------------------------

These two Functions below, will put all of the desired (see~read the differences between the two functions below) items in an Object, into an objectlist:

http://docs.textadventures.co.uk/quest/ ... ldren.html
http://docs.textadventures.co.uk/quest/ ... jects.html

if you want to do the same for specifically the Player Object, you can use this too:

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

or, if you want~need to (or can: the very lazy way, lol), you can use an objectlist containing every single object in your entire game:

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

------------------

As for the water issue, the best way (or you can use the 'not' negation keyword instead) would be to give your Objects an Attribute that distinguishes that Object as a water vs non-water/other Object, for example (using a String Attribute as it gives more versatility, but if you rather you can use a Boolean Attribute too, or there's also using an Object Type and its Inherited Attribute, too):

using a String Attribute:

(Object Name: fresh_water)
Attribute Name: type_of_object
Attribute Type: string
Attribute Value: water

(Object Name: dirty_water)
Attribute Name: type_of_object
Attribute Type: string
Attribute Value: water

(Object Name: holy_water)
Attribute Name: type_of_object
Attribute Type: string
Attribute Value: water

(Object Name: poisoned_water)
Attribute Name: type_of_object
Attribute Type: string
Attribute Value: water

(Object Name: cocacola)
Attribute Name: type_of_object
Attribute Type: string
Attribute Value: soda

(Object Name: pepsi)
Attribute Name: type_of_object
Attribute Type: string
Attribute Value: soda

(Object Name: rootbeer)
Attribute Name: type_of_object
Attribute Type: string
Attribute Value: soda

(Object Name: green_tea)
Attribute Name: type_of_object
Attribute Type: string
Attribute Value: tea

(Object Name: black_coffee)
Attribute Name: type_of_object
Attribute Type: string
Attribute Value: coffee


using a Boolean Attribute:

(Object Name: fresh_water)
Attribute Name: IsWater
Attribute Type: boolean
Attribute Value: true

(Object Name: dirty_water)
Attribute Name: IsWater
Attribute Type: boolean
Attribute Value: true

(Object Name: holy_water)
Attribute Name: IsWater
Attribute Type: boolean
Attribute Value: true

(Object Name: poisoned_water)
Attribute Name: IsWater
Attribute Type: boolean
Attribute Value: true

(Object Name: cocacola)
Attribute Name: IsWater
Attribute Type: boolean
Attribute Value: false

(Object Name: pepsi)
Attribute Name: IsWater
Attribute Type: boolean
Attribute Value: false

(Object Name: rootbeer)
Attribute Name: IsWater
Attribute Type: boolean
Attribute Value: false

(Object Name: green_tea)
Attribute Name: IsWater
Attribute Type: boolean
Attribute Value: false

(Object Name: black_coffee)
Attribute Name: IsWater
Attribute Type: boolean
Attribute Value: false


using an Object Type (Inherited Attribute):

Object Type Name: water_type
Object Type Attribute(s): (optional, but not necessary to add~create any for just this 'water vs non-water' differentiation)

Object Type Name: soda_type
Object Type Attribute(s): (optional, but not necessary to add~create any for just this 'water vs non-water' differentiation)

Object Type Name: tea_type
Object Type Attribute(s): (optional, but not necessary to add~create any for just this 'water vs non-water' differentiation)

Object Type Name: coffee_type
Object Type Attribute(s): (optional, but not necessary to add~create any for just this 'water vs non-water' differentiation)

(Object Name: fresh_water)
Inherited Attribute: water_type

(Object Name: dirty_water)
Inherited Attribute: water_type

(Object Name: holy_water)
Inherited Attribute: water_type

(Object Name: poisoned_water)
Inherited Attribute: water_type

(Object Name: cocacola)
Inherited Attribute: soda_type

(Object Name: pepsi)
Inherited Attribute: soda_type

(Object Name: green_tea)
Inherited Attribute: tea_type

(Object Name: black_coffee)
Inherited Attribute: coffee_type


------------------------------------------

which allows you to check for this Attribute and its Value, via an 'if' Script inside of the 'foreach' Function...

the examples below is now showing the complete scripting coding (you got to still actually create the Objects and Attributes as shown above, of course) for doing what you want:

using String Attributes:

objectlist_variable = GetDirectChildren (small_sack)
foreach (object_item, objectlist_variable) {
if (GetString (object_item, "type_of_object") = "water") {
RemoveObject (object_item)
} else if (GetString (object_item, "type_of_object") = "soda") {
msg ("You drink the soda, Aaahhh, so good!")
} else if (GetString (object_item, "type_of_object") = "tea") {
msg ("Tea is not your favorite drink, but you can handle it")
} else {
msg ("(You spit out the coffee, as you can't stand the stuff!)")
}
}


using Boolean Attributes:

objectlist_variable = GetDirectChildren (small_sack)
foreach (object_item, objectlist_variable) {
if (GetBoolean (object_item, "IsWater")) {
RemoveObject (object_item)
} else {
msg ("You drink down the liquid regardlessly, even if it's coffee...")
}
}


using Object Types (Inherited Attributes):

objectlist_variable = GetDirectChildren (small_sack)
foreach (object_item, objectlist_variable) {
if (DoesInherit (object_item, "water_type")) {
RemoveObject (object_item)
} else if (DoesInherit (object_item, "soda_type")) {
msg ("You drink the soda, Aaahhh, so good!")
} else if (DoesInherit (object_item, "tea_type")) {
msg ("Tea is not your favorite drink, but you can handle it")
} else {
msg ("(You spit out the coffee, as you can't stand the stuff!)")
}
}

jaynabonne
05 Jan 2016, 12:57
Using a combination of the above two responses gives a possibly simpler alternative:


removed = false
children = GetDirectChildren (small_sack)
foreach (child, children) {
if (not child = fresh_water and not child = dirty_water) {
RemoveObject (object_item)
removed = true
}

if (removed) {
msg("You can only place water in the sack.")
}
}

The extra "removed" logic is so that you only get the message once even if there are multiple items removed.

XanMag
05 Jan 2016, 15:06
Ha. I'm getting a little closer to not being a total code idiot! Getting closer... inch by inch... :lol:

OurJud
05 Jan 2016, 15:54
XanMag wrote:Ha. I'm getting a little closer to not being a total code idiot! Getting closer... inch by inch... :lol:

And better than my hacks :D