Changing Exits on object use

I have a Bus object, and I am making it "move" back and forth by making one of two exits on the bus become visible or invisible.

To do this, I have a Bus Pass and a Driver.

When I use the bus pass on the driver, the bus pass executes the following code:

if (Bus.stop = 1) {
  msg ("You show your pass to the driver, who proceeds to drive you to the Farm.")
  MakeExitInvisible (Out to Bus Depot)
  MakeExitVisible (Out to Farm)
  set (Bus, stop, 2)
else if (Bus.stop = 2) {
  msg ("You show your pass to the driver, who proceeds to drive you to the Bus Depot.")
  MakeExitInvisible (Out to Farm)
  MakeExitVisible (Out to Bus Depot)
  set (Bus, stop, 1)

On the Bus, I have an attribute named "stop" that has an integer value of 1. So this script should flip it back and forth between 1 and 2. However, here's the error I get:

Error running script: Error compiling expression 'stop': Unknown object or variable 'stop'

I have a Bus object and it has the attribute "stop". So I'm not sure why it isn't seeing that attribute.

Any ideas?

That code is trying to set the value of an attribute whose name is stored in the string variable stop.

You haven't got a variable called stop defined anywhere in the code.
set is designed for when you're not always changing the value of the same attribute.

If you just want to change the value of the "stop" attribute, you would use:

Bus.stop = 2


Bus.stop = 2

If you really want to use set, you could do:

set (Bus, "stop", 1)

but there is no reason to do it like that.

Thanks, it was unclear to me the difference between "set a variable or attribute" and "set an object's attribute". It's working now as I expected.

It's hard to explain the meaning of "set" sometimes.

Most times, you can just use the simpler notation.

Here's a bit of code you might see in an RPG, to give an example of the kind of situations in which set is actually useful.

foreach (stat, Split("strength;lore;grade_level;shoplifting;trash_talking;balls;weirdness;sanity")) {
  set (player, stat, 4)

That's code to set all of a player's stats ot the same starting value; the same as:

player.strength = 4
player.lore = 4
player.grade_level = 4
player.shoplifting = 4
player.trash_talking = 4
player.balls = 4
player.weirdness = 4
player.sanity = 4

You would also use set if you want to, for example, pick a random stat to add a point to:

stat = PickOneString(Split("strength;lore;grade_level;shoplifting;trash_talking;balls;weirdness;sanity"))
value = GetInt (player, stat)
set (player, stat, value + 1)

I know the examples probably aren't relevant to your game; but it might be useful to see some circumstances where set is beneficial.

Thanks, I appreciate the explanation. I actually might want to use something like this to initialize a bunch of attributes for a sequence of events a player may have to restart from scratch several times.

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