If and If then

Deckrect
25 Jun 2016, 21:17
i decided starting a side project as study, doing a regular parser game as we mostly see around.

I was making every object in the game as scenery, so i would hide the verbs and let player start typing. However, i met the first problem with a bedroll.

As i hide the items, i need to place them as a description for the player. it cannot be at the room's description, as the player is able to take the bedroll. So, i found interesting if the Object:room would check if both the bedroll is in room and if it is not in player's inventory. This case would reveal the bedroll was inside the room, but as it is not in inventory, the room description should print a massage.

However i don't know how check two conditions and only if both are ok, then get the result. Can the GUI do it?

jaynabonne
26 Jun 2016, 06:09
There is a feature in Quest that allows objects to contribute their own descriptions to the room description if they are not held - but only if they are visible. Since you're hiding them, I don't know if it would work.

If you wanted to try it out, click on the "game" object and then the "Features" tab. Then turn on "In-room descriptions: additional text which each object contributes to a room description". This will add an additional feature to an object's "Setup" tab, which is "In-room description". That description will then be added automatically onto the end of the room description for each object that has that field.

Once the object is taken, its "in-room description" will disappear from the room description.

As far as the text processor goes, it's fairly limited. I don't know if it can handle more complex expressions. You might be able to nest the "if"s.

HegemonKhan
26 Jun 2016, 07:01
if that method of Jay's doesn't work for them as/using the 'scenery=true' Boolean Attribute ... then you're just going to have to in the action's scripting: set the 'scenery' back to 'false' (briefly), so you can act upon it, and then change it back to 'true' after you've done the action.

Deckrect
26 Jun 2016, 10:15
No, guys. In room description is not an option for me.

It would be perfect if I could check two conditions and only if both gets satisfied I get the result.

HK, I think I don't understand your suggestion.

The Pixie
26 Jun 2016, 12:05
You only need to check one thing. If the bedroll is in the room, it is not in the inventory. You can use the text processor to conditionally add text:
This is an odd room.{if bedroll.parent=this_room:There is a bedroll on the ground.}

The parent attribute is where the thing is. You will need to change my_room to whatever the room is.

If you really do have two conditions, the text processor is not up to that. Set the room description to be a script instead of text (if you have already written text copy-and-paste it somewhere else for now - you will lose it) and use an if command linking the two conditions with and.
if (bedroll.parent=this_room and other_object.parent=this_room) {
msg("This is an odd room. There is a bedroll on the ground.")
}
else {
msg("This is an odd room.")
}

HegemonKhan
27 Jun 2016, 00:01
Also, the Boolean Logic / Truth Tables involved:

https://en.wikipedia.org/wiki/Truth_table
https://en.wikipedia.org/wiki/Boolean_algebra (this link is a bit more math/physics heavy/focused however)

AND:

true and true -> TRUE
false and true -> FALSE
true and false -> FALSE
false and false -> FALSE

conceptual example:
if you get a 70 or higher score on both test 1 and test 2, you pass the class. If you get a 70 or greater on only one of the tests or none of the tests, you fail the class.

code example:
if (player.test_1.score > 70 and player.test_2.score > 70) { // if both conditions are true, it returns TRUE and thus activates the 'msg' Script below:
-> msg ("You passed the class!")
} else { // since both conditions aren't true, it returns FALSE and thus the 'else's msg' Script is activated instead:
-> msg ("You failed the class...")
}

OR:

true or true -> TRUE
false or true -> TRUE
true or false -> TRUE
false or false -> FALSE

conceptual example:
if you get a 70 or higher score on test 1 or a 70 or higher score on test 2, you pass the class. If you get a 70 or higher on both tests, then of course, you also pass the class. But, if you get lower than 70 on both tests, you of course fail the class.

code example:
if (player.test_1.score > 70 or player.test_2.score > 70) { // Only (a minimum requirement of) one of the conditions needs to be true, for it to return TRUE and thus activates the 'msg' Script below:
-> msg ("You passed the class!")
} else { // since neither of the test scores are 70 or above, it returns FALSE and thus the 'else's msg' Script is activated instead:
-> msg ("You failed the class...")
}

NOT (Negation):

(not) true -> FALSE
(not) false -> TRUE

conceptual examples:
HK is not a famale.
Sarah is not a male.

code example (using/inside-of an 'orc' Object's 'fight' Verb):

if (not orc.dead) {
-> msg ("You fight and kill the orc")
-> orc.dead = true // the orc is set to being dead, as you just killed it.
} else {
-> msg ("The orc is already dead, silly.")
}

VS the same thing, but with/when not using negation ('not'):

if (orc.dead) {
-> msg ("The orc is already dead, silly.")
} else {
-> msg ("You fight and kill the orc")
-> orc.dead = true // the orc is set to being dead, as you just killed it.
}

VS the opposite grammer logic:

if (not orc.alive) {
-> msg ("The orc is already dead, silly.")
} else {
-> msg ("You fight and kill the orc")
-> orc.dead = true // the orc is set to being dead, as you just killed it.
}

VS the same thing, but with/when not using negation ('not'):

if (orc.alive) {
-> msg ("You fight and kill the orc")
-> orc.dead = true // the orc is set to being dead, as you just killed it.
} else {
-> msg ("The orc is already dead, silly.")

Deckrect
01 Jul 2016, 02:19
Ha ha! The AND particle was the missing thing. It used to be this way at the old days of BASIC, but I found it would be too easy and not probable because the GUI was missing a so basic resource. I see I will have to code these parts. But will be a minor issue.

Thank you, people.

HegemonKhan
01 Jul 2016, 03:20
in normal (C++, Java, Python, etc) programming, they use the symbols ('&&', '||', '!VARIABLE', '=='), but for quest, to make it more non-coder friendly, Alex programmed in to use 'and', 'or', 'not VARIABLE' (or the alternative but symbolic not: '<>'), and just '=' for both assignment and comparison operations (the parser handles it for us, in whether it's an assignment vs comparison statement/context).

So, with quest, you cause use nesting or the logic operators or both:

if (player.sex = "male") {
-> if (player.specialization = "combat") {
->-> // selection from 'player.male_combat_class_stringlist_attribute'
-> } else if (player.specialization = "magic") {
->-> // selection from 'player.male_magic_class_stringlist_attribute'
-> }
} else if (player.sex = "female") {
-> if (player.specialization = "combat") {
->-> // selection from 'player.female_combat_class_stringlist_attribute'
-> } else if (player.specialization = "magic") {
->-> // selection from 'player.female_magic_class_stringlist_attribute'
-> }
}

if (player.sex = male and player.specialization = "combat") {
-> // selection from 'player.male_combat_class_stringlist_attribute'
} else if (player.sex = male and player.specialization = "magic") {
-> // selection from 'player.male_magic_class_stringlist_attribute'
} else if (player.sex = female and player.specialization = "combat") {
-> // selection from 'player.female_combat_class_stringlist_attribute'
} else if (player.sex = female and player.specialization = "magic") {
-> // selection from 'player.female_magic_class_stringlist_attribute'
}

(too lazy to show using both... but I think you get the idea of it already)

Deckrect
01 Jul 2016, 13:02
May I operate this double conditions on GUI? Or do I type the code in order to make it work?

Deckrect
01 Jul 2016, 13:09
Oh, by the way, I tried checking if the bedroll is in room. What happens is if the bedroll is in inventory, the game takes it as in room too. I will check the code to see if it matches the same code you suggested, HK.

My last working hours were dedicated to some texts and making the game less ugly than it looked. I hope getting permission for using the chosen background texture.

HegemonKhan
01 Jul 2016, 14:28
Dectrect wrote:May I operate this double conditions on GUI? Or do I type the code in order to make it work?


I'm not very familiar with the GUI~Editor's [xxx] Script's options... there's probably options to do so, but I'm not aware of them. Instead, if I'm trying to help someone through the GUI~Editor, I "cheat", using the [expression] option, as this let's you directly type/code in the expression you want, hehe.

for example with the 'if' Script:

if -> [EXPRESSION] -> (see below)

if [EXPRESSION] player.sex = " male" and player.specialization = "combat"

(there's a bit of confusion/differences between using the GUI~Editor and directly in-code, as the GUI~Editor will handle some things for you, such as putting strings automatically into double quotes and of course all of the bracket stuff too, whereas in code, you got to do it yourself, GUI~Editor vs In-Code examples below)

(compare this below to the GUI~Editor's [expression] input above):
if (player.sex = "male" and player.specialization = "combat") { /* scripts */ }

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

GUI~Editor: 'print a message' Script -> [text] -> (see below)
print [message] Hi, my name is HK.
~VS~
in-code: msg ("Hi, my name is HK.")

~VS~

player.alias = "HK"

GUI~Editor: 'print a message' Script -> [run as script] -> (see below)
print [expression] "Hi, my name is " + player.alias + "."
~or using the text processor commands~
print [expression] "Hi, my name is {player.alias}."
-----
~VS~
in-code: msg ("Hi, my name is " + player.alias + ".")
~or using text processor commands~
in-code: msg ("Hi, my name is {player.alias}.")

-----------

Dectrect wrote:Oh, by the way, I tried checking if the bedroll is in room. What happens is if the bedroll is in inventory, the game takes it as in room too. I will check the code to see if it matches the same code you suggested, HK.


there's various Scopes you can use:

(these are just Functions that return an ObjectList Attribute of specific Object items)

http://docs.textadventures.co.uk/quest/scopes.html (I'm still confused about the difference between some of them, lol. Such as 'reachable' vs 'visible')

and there's the:

http://docs.textadventures.co.uk/quest/scripts/
http://docs.textadventures.co.uk/quest/functions/ (categorical order)
http://docs.textadventures.co.uk/quest/ ... tions.html (alphabetical order)
http://docs.textadventures.co.uk/quest/ ... ments.html (briefly mentions about on some of them)
http://docs.textadventures.co.uk/quest/ ... verbs.html (Pixie's Guide on using 'displayverbs' and 'inventoryverbs')

'Got', 'Contains', 'ListContains', 'DictionaryContains'

'displayverbs' and 'inventoryverbs'

how could I forget the "HK's lazy" ones, lol?! : the 'Alls': AllObjects(), AllExits(), AllCommands(), AllTurnscripts()

the 'populate/format' (generally not often used by the game maker) internal/system/quest using Functions

and probably a few more I'm forgetting...

Deckrect
01 Jul 2016, 15:27
Dude! Wonderful idea this expression cheating thing!

I will try this one. Once again you gave me a lot of material to study. Lol