Code Logic Question[SOLVED]

Anonynn
05 Jul 2016, 21:07

So I redesigned my water system to make it more simple and it works great, except for one little part. On the "water container object" (waterskin) there is a verb that checks for a "watersource boolean". This verb is called "Fill". In theory, if there is a watersource=True, then it should fill the water container object but the player can currently fill the container anywhere they want.

So the water object is: fresh_water, attribute boolean, watersource
The water container is: waterskin, attribute boolean, full, attribute boolean fresh_water, attribute boolean dirty_water,

if (waterskin.full=False) {
if (fresh_water.watersource=True) {
msg ("
You fill your waterskin with the fresh water!! It looks delicious!
")
waterskin.full = True
waterskin.fresh_water = True
}
else if (dirty_water.watersource=True) {
msg ("
You fill your waterskin with some dirty water. It looks...disgusting.
")
waterskin.full = True
waterskin.dirty_water = True
}
else {
msg ("
You'll need something to fill it with first!
")
}
}
else if (waterskin.full=True) {
msg ("
You'll need to dump, or drink the old contents first!
")
}

I know I'm missing SOMETHING. But what?


The Pixie
05 Jul 2016, 21:23

Look at the second line. Why would fresh_water object not be a watersource? The freshwater object always has watersource set to true. If the waterskin is not full, then the second line will always be true, so the skin gets filled with clean water every time.

What you really want to do is to check what water source is present in the room, if any, and see if that is clean or dirty.

By the way, you do not need to test a Boolean against a value:

if (waterskin.full=False) {
->
if (not waterskin.full) {

Also, you do not need two flags on the water source for clean and dirty. If it is clean, it is not dirty. You just need the one flag (I suggest dirty, because mixing clean and dirty will make dirty).


Anonynn
07 Jul 2016, 05:53

This is what I went with :) Thanks for pointing out my dumminess Pix!

if (waterskin.full=True) {
msg ("
You'll need to dump, or drink the old contents first!
")
}
else {
if (ListContains(ScopeVisible(), fresh_water)) {
msg ("
You fill your waterskin with some fresh water!! It looks delicious!
")
waterskin.full = True
waterskin.fresh_water = True
}
else if (ListContains(ScopeVisible(), dirty_water)) {
msg ("
You fill your waterskin with some dirty water. It looks...disgusting.
")
waterskin.full = True
waterskin.dirty_water = True
}
else {
msg ("
You'll need something to fill it with first!
")
}
}