And ; Or Statements

Welsh_Willis
Hello all, I'm new here but I am familiar to forums and scripting.
I've trawled these forums for a few hours, to no success.

I'm wondering how you can implement and ; or statements in script. I only want to cut down on the 'If's to keep it tidy. Cases will not work. My example is below.

if (Contains (Book Shelf,Book1)) {
if (Contains (Book Shelf,Book2)) {
if (Contains (Book Shelf,Book3)) {
msg ("You notice a small button on the top shelf. You press it and a loud 'CLUNK' comes from behind the book shelf. The book shelf starts to rotate 90 degrees revealing a secret room.")
UnlockExit (usecroom)
MakeExitVisible (usecroom)
MakeObjectInvisible (Book1)
MakeObjectInvisible (Book2)
MakeObjectInvisible (Book3)
SetObjectFlagOn (Book Shelf, "open")
}
else {
msg ("A very tall solid oak book shelf. There are three shelves that start at chest height on top of a built in cabinet. The lower shelf is full and has books on oceans, deep seas and large lakes. The middle shelf, just at arms length, has books on mountains, great plains and desserts. This shelf is also full. The top shelf which is too high for you to reach has books on rockets, stars and planets. This shelf has a book missing.")
}
}
else if (Contains (Book Shelf,Book3)) {
msg ("A very tall solid oak book shelf. There are three shelves that start at chest height on top of a built in cabinet. The lower shelf has books on oceans, deep seas and large lakes. This shelf is full. The middle shelf, just at arms length, has books on mountains, great plains and desserts. This shelf has a book missing. The top shelf which is too high for you to reach has books on rockets, stars and planets. This shelf is also full.")
}
else {
msg ("A very tall solid oak book shelf that seems to be built into the wall. There are three shelves that start at chest height on top of a built-in cabinet. The lower shelf has books on oceans, deep seas and large lakes. This shelf is full. The middle shelf, just at arms length, has books on mountains, great plains and desserts. There is a book missing. The top shelf which is too high for you to reach has books on rockets, stars and planets. That too has a book missing.")
}
}
else if (Contains (Book Shelf,Book2)) {
if (Contains (Book Shelf,Book3)) {
msg ("A very tall solid oak book shelf. There are three shelves that start at chest height on top of a built in cabinet. The lower shelf has books on oceans, deep seas and large lakes. There is a book missing. The middle shelf, just at arms length, has books on mountains, great plains and desserts. This shelf is full. The top shelf which is too high for you to reach has books on rockets, stars and planets. This shelf is also full.")
}
else {
msg ("A very tall solid oak book shelf. There are three shelves that start at chest height on top of a built in cabinet. The lower shelf has books on oceans, deep seas and large lakes. There is a book missing. The middle shelf, just at arms length, has books on mountains, great plains and desserts. This shelf is full. The top shelf which is too high for you to reach has books on rockets, stars and planets. This shelf also has a book missing.")
}
}
else if (Contains (Book Shelf,Book3)) {
msg ("A very tall solid oak book shelf. There are three shelves that start at chest height on top of a built in cabinet. The lower shelf has books on oceans, deep seas and large lakes. There is a book missing. The middle shelf, just at arms length, has books on mountains, great plains and desserts. This shelf also has a book missing. The top shelf which is too high for you to reach has books on rockets, stars and planets. This shelf is full.")
}
else {
msg ("A very tall solid oak book shelf. There are three shelves that start at chest height on top of a built in cabinet. The lower shelf has books on oceans, deep seas and large lakes. There is a book missing. The middle shelf, just at arms length, has books on mountains, great plains and desserts. There is also a book missing. The top shelf which is too high for you to reach has books on rockets, stars and planets. That too has a book missing.")
}


The purpose of the above code is the different 'Look at' versions of a book shelf (that has a puzzle aspect to it) depending on what and how many 'books' are in the book shelf at the time.
I'm making sure every possibility can be explored with 3 different books. 3 books, 3 shelves, 8 possible out comes of a message including no books on the shelves. (A particular book can only go on it's matching shelf.)

My question is: instead of having (in english)
if book shelf contains book 1
if book shelf contains book 2
if book shelf contains book 3 then...
elseif
elseif... ect ect

Could I use: If Book Shelf contains Book1 and Book2 and Book3 then...

FYI I did already find someone throw an example using 'If expression:' and I tried and failed. Tried different combinations of code and symbols, obviously failed. I even tried in Gui mode - If: Object Contains Parent: Book Shelf Contains Child: Expression Book1 and Book2 and Book3. Still nothing.
If anyone has a solution I would be most grateful, as would a few others I suspect. Solution in code form preferable.

Silver
You could create an integer attribute thing.

So you put book one on the shelf and then in the code you'd add:

books.shelf = books.shelf + 1

Then in your script above you'd do something like:

if books.shelf = 3


(I probably haven't explained that 100% correctly)

jaynabonne
if (Contains (Book Shelf,Book1) and Contains (Book Shelf,Book2) and Contains (Book Shelf,Book3)) {
//...

Silver
Note in my example you'd need to set it up in the start script:

books.shelf = 0


I think. I only learned this myself yesterday :lol:

Silver
The useful thing I found about the integer is that you can employ the text processor.

>look at bookshelf

msg ("it's a dusty old bookshelf {if books.shelf=3:that has three books sitting on it}{if books.shelf=2:that has two books sitting on it}{if books.shelf=1:that has a solitary book on it}{if books.shelf=0:that unfortunately has no books sitting on it}.")

Silver
Although I can see that my suggestion above relies on them being generic books.

HegemonKhan
Jay has already given the answer, but I'll echo it in my words (which will likely be more confusing than Jay's, lol)

with using 'and' and~or 'or' conditional-connectors:

I'm betting that you're doing:

if (Contains (Book Shelf,Book1) and (Book Shelf,Book2)) {

however, in quest, you got to tell it (what is) the command for your 2nd 'Contain' too, see below:

if (Contains (Book Shelf,Book1) and Contains (Book Shelf,Book2)) { script }

----

I think this could work too:

if (Contains ( (Book Shelf,Book1) and (Book Shelf,Book2) ) ) { script }

or

if ( Contains ( Book Shelf,Book1 and Book Shelf,Book2 ) ) { script }

jaynabonne

I think this could work too:

if (Contains ( (Book Shelf,Book1) and (Book Shelf,Book2) ) ) { script }

or

if ( Contains ( Book Shelf,Book1 and Book Shelf,Book2 ) ) { script }



No, they don't. The Contains function takes two objects, and it returns a boolean saying whether the second is contained in the first. You can only pass those two objects.

And

(Book Shelf,Book1) and (Book Shelf,Book2)


and

Book Shelf,Book1 and Book Shelf,Book2  

have no meaning. You can only "and" boolean values together, which is what Contains returns.

Welsh_Willis
jaynabonne wrote:if (Contains (Book Shelf,Book1) and Contains (Book Shelf,Book2) and Contains (Book Shelf,Book3)) {
//...
}


Thanks Jay. I will try it out on a separate file see what happens. I had a feeling it was the placements of brackets that was eluding me :? But between you and HK I have solved a lot of my problems already trawling these forums :lol: I'm pleased with the community here :D

I will check back with my results soon.

Welsh_Willis
@ Silver : The int script is fine as you said for generic types but mine is more specific. Once I release my game you'll understand.

Silver
Well you can do it along with specifics; its how I work anyway as I prefer to reveal objects within a descriprion rather than a list. It would be quite complex with your scenario though.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums