[solved] Question on Status Attributes - displaying a maximum value

So, I kinda had this solved in the past but completely forgot about it.
The player has an LP (life points) status attribute and also a maximum LP attribute.

How can I display both values in a single status attribute line?

LP: ! / {player.max_lp}
&
LP:! / " + player.max_lp + "
didn't work and now I'm kinda clueless...

Also, I prefer to avoid JS custom status panes since this a bit too complicated for me yet.


Just remembered...
I put both into a single string value and display that in the status.

set (player, "lp", 10)
set (player, "max_lp", 10)
player.life_points_string = "LP: " + player.lp + " / " + player.max_lp + ""

That's the most common way of doing it.

Most often, you'd use the script attribute changedlp to set the string attribute, so that it changes automatically every time the player gains or loses LP.


Alternatively, you could have a changedmax_lp script something like:

DictionaryAdd (this.statusattributes, "lp", "LP: ! / "+this.max_lp)

So every time the max changes, it adds the "lp" entry to the status attributes, but with the new max in the string.


Just, how exactly do changed scripts work?


Changescripts are script attributes whose name is "changed" followed by the name of another attribute of the same object. Whenever an attribute is changed, Quest checks if there is a corresponding changescript, and runs it.

Within the changescript, there may be a special variable oldvalue which contains the old value of the attribute.

So, for example, your changedlp might simply be:

this.life_points_string = "LP: " + this.lp + " / " + this.max_lp

Though in reality, a lot of people already have a changedlp script that does a couple of other things too:

if (this.lp < 0) {
  msg ("You are dead!")
  finish()
}
else if (this.lp > this.lp_max) {
  this.lp = this.lp_max
}
else {
  this.life_points_string = "LP: " + this.lp + " / " + this.max_lp
}

(that means that anywhere you increase or reduce the player's LP, the changescript will automatically kick in to make sure that healing items don't raise it over the max; or trigger a 'game over' screen if LP drops below zero)


this.life_points_string = "LP: " + this.lp + " / " + this.max_lp
if (this.lp < 0) {
  msg ("You are dead!")
  finish()
}
else if (this.lp > this.lp_max) {
  this.lp = this.lp_max
}
else {
  this.life_points_string = "LP: " + this.lp + " / " + this.max_lp
}

I have all of this already but I still don't understand how or where comes a changed script in. Absolutely no clue, sorry...


Do you mean you don't know how to add an attribute?

If you're on the desktop version:

  • Go to the "Attributes" tab of the player object
  • Create an attribute called "changedlp"
  • Set its type to "Script"
  • Whenever you change, player.lp, Quest will run the script player.changedlp

(I think there might be another way to do it, but I don't use the desktop version)

If you're using the web editor:

  • Go to the "Features" tab of the player object, and tick "Run an initialisation script"
  • Go to the "Initialisation" tab
  • Enter the script:
    this.changedlp => {
      // change script goes here
    }

just to echo mrangel:

'changedNAME_OF_ATTRIBUTE' change Scripts are special scripts that activate whenever/everytime the Value of your 'NAME_OF_ATTRIBUTE' Attribute, changes

for example:

[Object Name: player]
Attribute Name: strength
Attribute Type: int
Attribute Value: 0

[Object Name: player]
Attribute Name: changedstrength
Attribute Type: script
Attribute Value: (see below)

msg ("Player Strength: " + player.strength)

this 'changedstrength' change Script, will display your strength, everytime/whenever the Value of your 'strength' Integer Attribute changes

(you got to think a bit though, if you don't need/want stuff to happen every time an Attribute's Value changes, don't put it into a change script, but sometimes, it's also just unavoidable too, and the only thing you can do is to make the scripting as efficient as possible: less operations, so your game doesn't lag, but this is only for more extreme/rare cases of more complex coding, due to how fast modern computers are and how well quest itself was coding/programmed)

this makes these special changed scripts extremely useful, though they might cause issues, as they get high priority, in that they immediately activate whenever that Attribute's Value changes, but there might be other stuff that still has higher priority, or quest/game is already doing something, and the change script activates, "rudely butting in", which can then possibly mess up what quest/game was doing, as it then continues after the change script is done doing its thing

the other method in quest is to use the 'Turnscript' (or the 'Timer') Elements, which does offer you more control over when what scripts are activating (as you can enable/disable them), but it can get messy using them too, instead of the changed Scripts...

Turnscripts activate every internal turn: any action you do is always an internal turn (don't know/remember if mrangel/pixie found the internal turn mechanism and thus can control/alter it, or if they just use their own custom 'turn' Integer Attributes, controlling when they increase or not): an action is either (1) typing in something into the text command bar at the bottom of the screen, (2) clicking on an Object's Verb button, or (3) clicking on the blue hyperlinks in the big text box on the left

Timers are self explanatory, but they can easily be/become the most messy of all, again, for (hopefully) obvious reasons...

What makes Turnscripts/Timers useful over changed Scripts:

if you want to do multiple actions, you set the order that they're occurring within a Turnscript/Timer, which while you can do multiple actions within a changed Script, the difference is that the changed Script is already requiring some Value of some Attribute to change, which usually isn't involved when you just want do control multiple actions, and thus the usefulness of Turnscripts/Timers, as they completely allow you to control everything: via enable/disable them and also in that you're deciding/setting the order of the actions (scripting) within them


using the changed Scripts and/or Turnscripts/timers often go with using the 'statusattributes', when you need to update those Attributes that have multiple (usually Integer) Attribute Value's within them (such as a String Attribute used for displayment of min/max stats, for example: 999/999 Life), as the 'statusattributes' only display the current Value of the Attribute itself, but that means if you got a String, you need a method to change its Integer Attributes' Values within it, so that when the String Attribute is displayed by the 'statusattributes', it's displaying the current/new (correct) Integer Values within it, so a way to think about it: the 'statusattributes' just does DISPLAYMENT of the CURRENT Value of the Attribute itself, but if you got a String Attribute, that uses Integer Values within it, then you need a method for updating/changing those Integer Attributes, which can be done through the changed Scripts and/or the Turnscripts/Timers

there's some other uses too, but usually it involves wanting a min/max stat display, and thus a String Attribute with Integer Attributes within it, which is done usually via using the changed Script and/or Turnscript/Timer and the built-in 'statusattributes' displayment feature


if you want to control stuff, then you wouldn't use the change Scripts, you'd be using the Turnscripts/Timers (as you can enable/disable them as wanted/needed) and/or "set" Scripting/Actions (like using an Object's Verbs and/or a Command and/or the special 'start' Script of the 'game' Object, for some examples)


Sorry for the late response.

mrangel -I just couldn't understand the changedscript attribute. Where does it start and where is it placed! Or which part of the script must be in the changedscript! However, I've finally got it. Thanks for the help.
hegemonkhan -Thank you, this explanation was very helpful in understanding the basics of the changedscript.


Log in to post a reply.

Support

Forums