Attributes vs Flags?

I made an attribute for a room named "hasBeenVisited" and set it to false, then triggered a script on the exit. So my first time going through an exit displays a different message than after follow up movements through the same exit.

I can use attributes, and I can use flags. Does anyone have documentation on the difference between the two? Is there a point to using one or the other?

Are flags protected/ only able to be accessed by the parent object?


I can use attributes, and I can use flags. Does anyone have documentation on the difference between the two? Is there a point to using one or the other?

For this purpose, I would say, there is not much of a difference. A flag is an attribute with one of two possible values, true or false.
An attribute can be many things including the functionality of a flag. If you just have to check between two possible states the flag is enough.

Are flags protected/ only able to be accessed by the parent object?

No, you can access edit and check a flag from everywhere. However, the flag "hasBeenVisited" is not needed, because Quest has this flag built-in already. All objects have by default the flag called "visited" set to false

http://docs.textadventures.co.uk/quest/attributes/visited.html
http://docs.textadventures.co.uk/quest/attributes.html
https://docs.textadventures.co.uk/quest/tutorial/
https://docs.textadventures.co.uk/quest/tutorial/more_things_to_do_with_objects.html
http://docs.textadventures.co.uk/quest/tutorial/custom_attributes.html


Attributes are better used when you require more than one status on an object at once. For example, if an object could be damp, wet, soaked, dry, parched or arid whilst at the same time being full, or empty, or too light, just right or too heavy.

Although I'm sure someone with much more experience than me can find a definitively better example!


First time scripts are another option.


I can use attributes, and I can use flags. Does anyone have documentation on the difference between the two?

Quest doesn't have any specific concept of a 'flag'. It's just another name for an attribute. A few places in function names and in the GUI editor, the word "flag" is used to mean an attribute that is set to true or false, but people who are used to other languages might use it occasionally to mean other types of attributes.

They're just different names for the same thing.


@Curt

However, the flag "hasBeenVisited" is not needed, because Quest has this flag built-in already.

Not true. The core visited flag is set the first time the player enters a room. The OP's hasBeenVisited flag would be set the first time the player leaves the room. The similar names of these two might be confusing, but they serve different purposes and aren't interchangeable.


@Father

First time scripts are another option.

Good call, I was also going to suggest this.

If you want something different to display the first time some event happens, it may be simpler to use the features Quest already has for those purposes.

For example, your script could be:

firsttime {
  msg ("You leave the room.")
}
otherwise {
  msg ("You leave the room again.")
}

There is a similar (but less efficient) mechanism within the text processor. So anywhere there is some text, you can have it display differently the first time it is seen. For example, a room's description could include:

{once:You've never seen a light this bright as this before.}
{notfirst:The light is just as bright as the last time you looked.}

(I'm not sure why it was decided to use firsttime and otherwise in scripts, but once and notfirst in the text processor. It seems to me that it would make more sense to use the same words in both (firsttime and notfirst maybe), but we just have to remember which ones Quest uses)

It's also worth noting that the script version tracks the first time a particular script is run. So if you have the same script on two exits, it will show you the firsttime message the first time you use each exit (once for each exit). But with the text processor, if you have the exact same message in two places, the {once: block will consider them to be the same, and only appear for the one that the player comes across first.


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

Support

Forums