Changing variables within SpecialTopic

Can I somehow change a global variable within a SpecialTopic print routine? Looks to me like I can call an external routine by using <> within the print string but can I simply set a variable, e.g. variable=1? Thanks!

I tried this with a room description:

  desc = "
  Setting <<v>>\n
  <<v = 1>>\n
  Now <<v>>\n
  v = 0

and this was the result:

Setting 0
Now 1

So, yes, assignment is possible within an embedded expression, but a simple assignment will result in the value being included in the string (the second line that reads 1). This is true as well for globals, such as incrementing libGlobal.totalTurns instead of v.

Personally, I would call a function instead, to keep things clean and to avoid the side-effect.

Ah, I had to get to know the concept of global variables first. Now it works. Thanks!

Interesting quirk, whose can be used in at least one interesting manner: taking Jim’s test a step further, one can, for example:

" Now you gained more time: back to <<>>\n
  <<libGlobal.totalTurns = libGlobal.totalTurns-40>>\n
  Now, let's tackle this story with a more deliberate pace.. <<v>>\n

of course, there will be the need of avoiding embarassing things like, say, turn: -34 or like, but isn’t difficult with a little design effort…

kudos to both for the interesting thing, perhaps deserving its place in the budding T3 cookbook ? :wink:

Best regards from Italy,
dott. Piergiorgio.

1 Like

Well I’m glad I got this to work and I’m not gonna follow this up.

Side question, please forgive me for asking this here: Is there no such thing as a global variable in TADS? Like, “variable” instead of “object.variable”?

Kind regards,

I don’t believe there is such as thing as an unassociated global variable in TADS. The symbols that look like globals (such as gPlayerChar or gRoom) are #define macros referring to a property within an object instance (such as libGlobal.playerChar).

There might be some language feature that can be used for true global variables that are not members of a class or instance, but I’m unaware of it.


(Weird concept, though.)