Room Names and variable issues

Hi there, its been a while since I've been stumped. I want to implement a command that checks the active room the player is in for attribute roomname.explorable , and if its True, allows the player to 'explore' to find random items. I don't want to have to do this command for each room, I'd prefer to be able to create some script to check if the active room the player is in has the attribute, regardless of the name of the room itself. Is there a way to do that?


Had to edit to remove the < >


The game element has an attribute pov that has the current player object (which is normally an object named player, but it's safer not to assume that).

Every object has a virtual attribute parent, which points to the object that contains it.

In this case, you should probably use GetBoolean, which both checks that the attribute exists, and that it's true. This way, you don't need to worry about remembering to set explorable to false for all the rooms that aren't.

So your command script would look like:

room = game.pov.parent
if (GetBoolean (room, "explorable")) {
  // insert code here - you can use the variable 'room' to refer to the current room if you need it
}
else {
  msg ("You can't explore here!")
}

Oh my god this was EXACTLY what I was looking for, thank you thank you thank you so much. Can you point to where this is in the documentation so I can read further?

On further realization, this is close, but not quite what I was looking for. Maybe I'm just missing something (and it is 11 PM so its possible I am) but this is checking the player object, not the room? Why do I feel so stupid ?

Secondarily, can I set an attribute in real-time that isn't already set before game run?


this is checking the player object, not the room?

Did you copy it correctly?
game.pov is the player object
game.pov.parent is the room that contains the player object

can I set an attribute in real-time that isn't already set before game run?

Yes. But trying to check an attribute that hasn't been set yet will sometimes cause an error, so you have to be more careful how you do it.

For example, if (objectname.attributename = 5) { would be an error if it's not set. You'd have to use if (Equal (objectname.attributename, 5)) { instead; which is slightly slower.

There are a range of functions like HasInt (objectname, "attributename") which tell you if an attribute has been set. Others include HasScript, HasString, HasBoolean, and HasObject. If you're looking at an attribute that might not have been set, you need to check that it exists before you compare it to anything. (Equal and GetBoolean make it a little easier because they check automatically)


I had a case of the stupid, due to sleepiness. I was checking the player object not the room. Thanks again.

What I mean is to add an attribute to an item/room in runtime. IE if I have the following
room.item1 , with the attribute
item1.isitem = True
Can I do this in real time without first defining 'isitem' as an attribute before game start? Can I add the attribute 'isitem' to item1 , then set this new attribute as "True" ?


Can I do this in real time without first defining 'isitem' as an attribute before game start? Can I add the attribute 'isitem' to item1 , then set this new attribute as "True" ?

Yes.

(for those of us using the web editor, this is the only way to create attributes)

Like I said in the previous answer, you can do it but if you're setting an attribute after the game has started, then any code that might do something based on that attribute needs to check whether it exists.

As far as Quest is concerned, an attribute that hasn't been set is exactly the same as an attribute whose value is null.


Log in to post a reply.

Support

Forums