Can I "and" in a script? Instead of if

'''// Function to check the room sequence
function CheckSequence() {
if (ListCount(player.sequence) = 5) { // Assuming the sequence is 5 rooms long
if (StringListItem(player.sequence, 0) = "Room1" and
StringListItem(player.sequence, 1) = "Room2" and
StringListItem(player.sequence, 2) = "Room3" and
StringListItem(player.sequence, 3) = "Room4" and
StringListItem(player.sequence, 4) = "Room5") {
msg ("You've entered the rooms in the correct order and found the treasure!")
MoveObjectHere ("treasure")
player.treasureFound = true // Set the flag to true as the treasure has been found
} '''

It isn't correct. I know it isn't correct, but I do not know what to do. What should I do?


I have similar issues with the "and" operator, sometimes when I reverted back to graphic user interface, it automatically changes my code into what the quest app is familiar with

1 example:
if (game.pov.parent = room and fbi1.parent = game.pov.parent) {
msg ("yes")
}

Transformed into gui:
player is in room expression "room and fbi1.parent = game.pov.parent"
msg("yes")

There were many different examples, but I did not record them
I just spammed the if loops over and over again

if(game.pov.parent=room){
if(fbi1.parent=game.pov.parent){
}
}

As you might thought, this can lead to many accidental human errors, where the coder does not puts what happens on the else of each bracket, even if one is meticulous, it is also a lot of work, than to just use the "and" operator without being disrupted by the quest app gui changing the code


Looks like a Quest editor quirk. Code accepted if the line feeds are removed:

if (ListCount(player.sequence) = 5) {
  if (StringListItem(player.sequence, 0) = "Room1" and StringListItem(player.sequence, 1) = "Room2" and StringListItem(player.sequence, 2) = "Room3" and StringListItem(player.sequence, 3) = "Room4" and StringListItem(player.sequence, 4) = "Room5") {
    msg ("You've entered the rooms in the correct order and found the treasure!")
    MoveObjectHere ("treasure")
    player.treasureFound = true
  }
}

@daeun

I have similar issues with the "and" operator, sometimes when I reverted back to graphic user interface, it automatically changes my code into what the quest app is familiar with

This is because the GUI editor uses a regular expression to decide how to display the expression. It should still work. The GUI is really weird sometimes.

If you want to stop it doing things like this, you just need to change the expression to something that doesn't look like its default. For example:

if (room = game.pov.parent and fbi1.parent = game.pov.parent) {

or

if ((game.pov.parent = room) and (fbi1.parent = game.pov.parent)) {

@Jennifer
What language is the script you posted? You seem to have javascript syntax (Comments with // on the same line as other statements; and function CheckSequence() at the beginning, but you're using expressions like player.sequence which don't exist in javascript.

If this is Quest script, tidying up the lines so that the expression is all on one line should work fine. However, I would be more likely to use a single statement here (assuming that player.sequence is a stringlist; which it seems to be in your code).

if (Join(player.sequence, ";") = "Room1;Room2;Room3;Room4;Room5") {
  msg ("You've entered the rooms in the correct order and found the treasure!")
  MoveObjectHere (treasure)
  player.treasureFound = true
}

(I notice that you also had MoveObjectHere ("treasure"), which looks like a problem because "treasure" is a string, not an object. If it's an object name, it doesn't go in quotes)


Apparently my example do work just like mrangel said, I tried a demo and it did message "yes"

if (game.pov.parent = room and fbi1.parent = game.pov.parent) {
msg ("yes")
}

Unfortunately your two solutions aren't accepted by quest GUI as well, but yes, the code works and printed "yes" as well
Since both of your solutions have similar weird GUI's appearance, I will just post your code 2 since it looks more complicated

Code 2

if ((game.pov.parent = room) and (fbi1.parent = game.pov.parent)) {

I got GUI

if object attribute equals object expression (game.pov.parent=room) and (fbi1 Attribute parent = game.pov.parent)
print message yes


But perhaps, knowing the code works is enough for me, I will just update my game in code view screen which is a lot more readable


Log in to post a reply.

Support

Forums