Making a cocktail Redux (still need help)

I want a glass to turn into a new object (a cocktail) once it contains three ingredients, I thought I could do this by using a turn script, a series of nested IF commands, the code is below, I'm probably doing something naively wrong, but the change script suggested to me as a solution before is a bit daunting for me. Using browser version

if (Contains (Pint Glass,Celery)) {
if (Contains (Pint Glass,Ice)) {
if (Contains (Pint Glass,tomato juice)) {
AddToInventory (Virgin Mary)
RemoveObject (Pint Glass)
msg ("You made a Virgin Mary cocktail")
}
}
}


Again I would do it like I explained for the character having new inventory.
So you have a glass. If someone adds an ingredient swap it for a new object - the glass holding that ingredient. Then when they add another you swap it for the object holding 2 ingredients.

It means working with lots of objects but reduces massive IF scripting checking on loads of variables.


That strategy hadn't occurred to me! I may try that way, still curious why my turn script doesn't work though


Someone else will have to answer. My coding is rusty atm.


But surely only one check is needed -

If (contains (pint glass, ice, celery, tomato juice))

(Going by your code which I'm unfamiliar with)


I don't know who to have multiple conditionals on just one IF statement in the browser version, there is no 'and' option


But only one condition leads to the making of the cocktail, so why check the others (unless to give a description, but that can be handled by the use object code)


if (Contains (Pint Glass, Celery) and Contains (Pint Glass, Ice) and Contains (Pint Glass, Tomato Juice)) {
  AddToInventory (Virgin Mary) // or: MoveObject (Virgin Mary, player) // or: Virgin Mary.parent = player // or: set (Virgin Mary, "parent", player)
  RemoveObject (Pint Glass) // or: Pint Glass.parent = null // or: set (Pint Glass, "parent", null)
  msg ("You made a Virgin Mary cocktail")
}

I'm not sure what/how to can do online/web quest, but you need something to 'fire/activate/trigger' the 'mixing' checking scripting/action/event (see above in the code box), a: Verb, Command, Turncript, Timer, or a 'changed' Script Attribute (I think the only way for this, would be using an Objectlist Attribute for your 'Pint Glass', such as using the built-in ones: the 'Scope' Functions):

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

or, you'd have to create your own Objectlist Attribute for your 'Pint Glass' Object, and whenever an Object is moved to/into the 'Pint Glass' Object, you add it (as an Object reference) to your Objectlist Attribute, and in your 'changed' Script Attribute, it'd be like this:

if (ListContains (Pint Glass.NAME_OF_OBJECTLIST_ATTRIBUTE, Celery) and ListContains (Pint Glass.NAME_OF_OBJECTLIST_ATTRIBUTE, Ice) and ListContains (Pint Glass.NAME_OF_OBJECTLIST_ATTRIBUTE, Tomato Juice)) {
  AddToInventory (Virgin Mary) // or: MoveObject (Virgin Mary, player) // or: Virgin Mary.parent = player // or: set (Virgin Mary, "parent", player)
  RemoveObject (Pint Glass) // or: Pint Glass.parent = null // or: set (Pint Glass, "parent", null)
  msg ("You made a Virgin Mary cocktail")
}

I've got it work now, didn't have turn script enabled from start!

Conditional - the glass needs to contain all three items, but I can't list all three items in one IF command - can only add one item to the 'object contains...'


Yeah fair dos, I'm unfamiliar with the code as I'd do it the way I described.


do you have the '[EXPRESSION]' drop down choice/functionality?

if you do, change your script to this script option: [EXPRESSION]

and then just write (type, whatever, lol) in what I have in my previous post (changing it if the spelling/words/lower-upper-caps that you're using in your game), or see here:

if (Contains (Pint Glass, Celery) and Contains (Pint Glass, Ice) and Contains (Pint Glass, Tomato Juice))

otherwise, just do the nesting:

if (Contains (Pint Glass, Celery)) {
  if (Contains (Pint Glass, Ice)) {
    if (Contains (Pint Glass, Tomato Juice)) {
      // blah scripts...
    }
  }
}

though, this does have a bit of a hiccup... make sure the person playing is aware that they need all 3 of the ingredients, as this nesting design requires that they have the Objects in this order (the 2nd and 3rd Objects aren't recognized by the code unless you've got the needed Object/s before it). Just make sure the people playing are aware of this issue with the nesting code design.


Thanks both! I went for the nested option with a bit of smoke and mirrors swapping objects and it works fine. I didn't know you could use 'and', that should make things easier in future!


ya, quest makes it user friendly:

'AND' logical operator: and
'OR' logical operator: or
Negation ('NOT') logical operator A: not
// Negation ('NOT') logical operator B: <>

unlike other languages that use symbols, for examples (C++, Java):

'AND' logical operator: &&
'OR' logical operator: ||
'NOT' logical operator: !

but, the usual culprit (stumper) for most people is that you've got to do a full statement for each condition, for example:

if (CONDITION_1 LOGICAL_OPERATOR CONDITION_2 LOGICAL_OPERATOR CONDITION_3) { /* scripting */ }

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

if (game.color = "red" or "blue" or "yellow") { /* scripting */ }
// ERROR!

vs

if (game.color = "red" or game.color = "blue" or game.color = "yellow")  { /* scripting */ }
// NO error

a statement in quest coding:

Variable VARIABLES:

NAME_OF_Variable
or
NAME_OF_Variable OPERATOR VALUE_OR_EXPRESSION

Attribute VARIABLES:

NAME_OF_OBJECT.NAME_OF_ATTRIBUTE
or
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE OPERATOR VALUE_OR_EXPRESSION


if you're new to programming and/or logic, the here's how the logical operators work:

https://en.wikipedia.org/wiki/Truth_table

effectively, comparisons are Boolean (true/false, aka logic) operations:

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

/*
example:

game.color = "red"
if (game.color = "blue") {
// if ("red" = "blue) {
// if (false)  { ---> FALSE -> skip it's nested script: msg ("hi"), move to next script: } else if (game.color = "red") {
  msg ("hi")
} else if (game.color = "red") {
// } else if ("red = "red") {
// } else if (true) { ---> TRUE -> DO it's nested script: msg ("bye") 
  msg ("bye")
}
*/

if (true and true) ---> TRUE
if (true and false) ----> FALSE
if (false and true) ----> FALSE
if (false and false) ----> FALSE

if (true or true) ---> TRUE
if (true or false) ----> TRUE
if (false or true) ----> TRUE
if (false or false) ----> FALSE

-------

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

-------

if (not true or not true) ---> FALSE
// if (false or false) ----> FALSE

if (not true or true) ---> TRUE
// if (false or true) ----> TRUE

if (true or not true) ---> TRUE
// if (true or false) ----> TRUE

-----

if (not true and not true) ---> FALSE
// if (false and false) ----> FALSE

if (true and not true) ---> FALSE
// if (true and false) ----> FALSE

if (not true and true) ---> FALSE
// if (false and true) ----> FALSE

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

Support

Forums