Setting exit to visited = true

Jamie Furlong
22 Aug 2018, 03:18

I've assigned a boolean attribute called 'visited' within Game and set it to false. I've created an exit (exit1) and also given it the same visited attribute but set to true. Script to run on exit1 is:

DecreaseScore (20)
MoveObject (player, room2)
visited = true

In room2 I've included

if (exit1.visited=true) {
  msg ("You came through exit1")
}
else {
  msg ("you didn't come through exit1")
}

If I set exit1 attribute to 'true' then it prints "you came through exit1" whichever exit they chose and if I set exit1 attribute to 'false' then "you didn't come through exit1" is printed in room2, whichever exit they choose.

If I remove the visited attribute altogether on exit1 then I get:

Error running script: Error compiling expression 'sm.visited=true': CompareElement: Operation 'Equal' is not defined for types 'Object' and 'Boolean'

Somehow I need to set exit1's atttribute to 'true' on room2 only if they used this exit, but how do I do this?

Thanks in advance.


Pertex
22 Aug 2018, 06:58
I've assigned a boolean attribute called 'visited' within Game and set it to false. I've created an exit (exit1) and also given it the same visited attribute but set to true. Script to run on exit1 is:

DecreaseScore (20)
MoveObject (player, room2)
visited = true

Instead of 'visited = true' try 'exit1.visited=true'

An additional advice: better don't create a new attribute named 'visited'. There is an internal attribute with that name so it's better to use another name for userdefined attributes such as 'exitvisited'


Jamie Furlong
22 Aug 2018, 10:04

Thanks, Pertex. I'll bear those tips and points in mind. Meanwhile I've solved the problem a slightly different way by assigning an invisible room that gets added to the inventory as they pass through it. They don't see this happening but in the next visible room I can check to see if they have the invisible room in their inventory.


hegemonkhan
23 Aug 2018, 03:55

as Pertex' stated:

there's already a built-in 'visited' Boolean Attribute and functionality, which works for 'Object' and 'Exit' Elements (the Elements: Objects, Exits, Functions, Commands, Verbs, Turnscripts, Timers, Object Types, and etc --- are all, or only some of them -- meh, quest's OBJECTS of its internal coding, but don't confuse this deeper code stuff with the normal user level's usage of Objects: 'Room' Objects, 'Object' Objects, and 'Room+Object' Objects, aka the 'Object' Element that people use at the normal user level)

so use that (as it has a lot of built-in functionality already done for you)... or... make your own custom Attribute (but then you got to create all the functionality you want with it...)


http://docs.textadventures.co.uk/quest/elements/ (the "physical stuff" that you have to work with in quest: Objects, Exits, Functions, Commands, Verbs, Turnscripts, Timers, Object Types, etc)

http://docs.textadventures.co.uk/quest/elements/object.html (the built-in Attributes of Objects)

http://docs.textadventures.co.uk/quest/elements/game.html (the built-in Attributes of the special 'game' Game Settings and Publishing Info Object)

http://docs.textadventures.co.uk/quest/types/ (Attribute/Value/Data Types: Strings, Integers: ints, Doubles, Booleans, Object references/pointers, Scripts, Lists, Dictionaries, etc)

http://docs.textadventures.co.uk/quest/scripts/setting_variables.html

http://docs.textadventures.co.uk/quest/scripts/

http://docs.textadventures.co.uk/quest/functions/ (categorical order)
http://docs.textadventures.co.uk/quest/functions/index_allfunctions.html (alphabetical order)


also.... Pertex pointed out that:

there's a big difference between:

'Variable' VARIABLES:

strength = 100

visited = true // (example using 'true' as it's set Value, but you can set it to 'false' too/instead, of course)

and

'Attribute' VARIABLES:

// create ("orc") // creating an 'orc' Object
// create ("room_99") // creating a 'room_99' Object

orc.strength = 100

room_99.visited = true // (example using 'true' as it's set Value, but you can set it to 'false' too/instead, of course)


I think you're new to coding, right?

if so, this is a common big thing that people new to coding need to learn/understand and have trouble with (lots of posts/threads and our help response posts, trying to explain to them that they used 'Variable' VARIABLES, when they need to be using 'Attribute' VARIABLES, as these are much easier and better to use for the most part, and/or until they learn/understand when/where/how to use 'Variable' VARIABLES vs 'Attribute' VARIABLES: aka, you need to understand 'scope' and parent-child heirarchy, scripting's order of operations, and etc stuff that might be relevant that I'm forgetting. You not the first to have trouble with this stuff, it's a common problem/learning-curve for people new to coding)