Is it possible to have a permanent variable?

NinjaHero4265
10 Apr 2020, 20:33

So I'm working on a game and I'm trying to have a person be in the same room as the player and comment on stuff. So I thought to set a variable at the beginning of the room as a string dictionary called girlchoice1 with the key part being letters and the value thing being the questions. The only problem is that the game keeps forgetting the variable. Is there a way to make it permanent?


mrangel
10 Apr 2020, 21:22

An attribute lasts as long as the object it is attached to. You can use an attribute in the same way as a local variable, just give the variable name as objectname.attributename. If the girl in this case is an NPC, then making the variable something like girl.choice1 would make it accessible to your scripts until she is destroyed. (replacing girl with the actual object name if it's different). In the case of persistent variables that don't logically relate to a particular object in the game, it's normal to store them as either player.variablename, or game.variablename.


NinjaHero4265
10 Apr 2020, 21:57

I'm still not getting it to be completely honest. I'll just show you the code and then that may make things easier to comprehend.
Room Description Code:

MakeObjectVisible (Mila)
list remove (Weapon Wall.displayverbs, "Investigate")
list remove (Your Desk.displayverbs, "Investigate")
list remove (Note.displayverbs, "Investigate")
list remove (Your Monopad.displayverbs, "Investigate")
list remove (Bookcase.displayverbs, "Investigate")
list remove (Computer.displayverbs, "Investigate")
milachoice1 = NewStringDictionary()
dictionary add (milachoice1, "a", "\"What do you think of all this?\"")```

Most of that is because my game has two routes in this room and the girl "Mila" is only in one of them so just ignore all the displayverbs removing. Now to the next part.

Mila Verb, speak to, Code
```ShowMenu ("\"{player.alias}? What's on your mind?\" ", milachoice1, true) {
  if (result="a") {
    msg ("msg")
  }
  else if (result="b") {
    msg ("msg")
  }
}```

Again I want to find a way to make milachoice1 be able to be updated so I can have the player explore the room and have them get constant feedback from the girl. It doesn't seem to be able to do that right now as it forgets milachoice1 as the code moves. Can you please explain with code if possible?

mrangel
10 Apr 2020, 23:11
MakeObjectVisible (Mila)
list remove (Weapon Wall.displayverbs, "Investigate")
list remove (Your Desk.displayverbs, "Investigate")
list remove (Note.displayverbs, "Investigate")
list remove (Your Monopad.displayverbs, "Investigate")
list remove (Bookcase.displayverbs, "Investigate")
list remove (Computer.displayverbs, "Investigate")
Mila.choice1 = NewStringDictionary()
dictionary add (Mila.choice1, "a", "\"What do you think of all this?\"")

and

ShowMenu ("\"{player.alias}? What's on your mind?\" ", Mila.choice1, true) {
  if (result="a") {
    msg ("msg")
  }
  else if (result="b") {
    msg ("msg")
  }
}

NinjaHero4265
11 Apr 2020, 00:16

Thank you!