Question about adding a message when attributes reach a specific number.

Hello.

I'm not at all familiar with coding and I'm stuck on how to make a message appear when an attribute like "psychosis" reaches a 100, or 20, 30, ect.

Any advice would be appreciated.


Ok. Let's do it.
First create your attribute, what you will call "player.psy" (for short) and set it to a certain numaber. lets say 0. So, by using GUI you may set attribute, object "player", name "psy", value "0". Just keep in mind that attributes may be INT or STRING. The first it is treated as number and only numbers are possible. The second is a set of letter we use to call words, but for the machine, there is no such thing as words.

Once you have an attribute running, you can do things to it. The GUI has a function that increases and decreases an attribute, as long as it is an INT, but it does so only one by one. If you want rising in ten, for example, you need an expression like "player.psy=player.psy+10". It means whaterver the value is, the new value is the older one plus ten.

In order to make the game checking and displaying the massage, you need a conditional. It is the IF and THEN stuff. So, IF player.attribute=20, THEN "print massage "you feel earie" or "Jack feels earie".

The main part of the trick here will be where to place the script. If you want it happens when the attribute changes, you must put it in the same conditional that checks the attribute level. If you want it in a certain room, you may place in the "after entering" at the scripts tab. The object 'Game' also has a script tab, so you may check the condition, for example, every time the player enters a room. The specifics are about your project.

I hope it helped.


For something like this there's two ways to do it.

First: use an if statement to check the attribute every time you increase it.

Second: Use a changescript.

I think in the desktop editor, there's a button to attach a changescript to an attribute. I don't know, because I don't have a Windows computer to try it on.

In the web version, to add a changescript you'd put something like this in the object's initialisation script, the start script, or some other script (probably immediately after you create the attribute):

player.changedpsychosis => {
  // include the script here
}

The simplest thing to put in the changescript would be:

if (this.psychosis >= 100) {
  // whatever you want it to do
}

That will run any time the player's psychosis attribute changes if the new value is 100 or higher. If you only want it to trigger when the value first hits 100, and not run again while it stays over the limit, you'd change that to:

if (this.psychosis >= 100 and oldvalue < 100) {
  // whatever you want it to do
}

(The special variable oldvalue in a changescript contains whatever the attribute was before)

Hope that helps.


Awesome. Thank you for the help. I have now learned how to make a printed message with an (if, then) expression.


The if/then/else statements will become the bread and butter of your games, along with flags.

For example, let's say you want to tie a hook to a fishing rod. Now obviously you can use the editor to plan for the event, so you set up the two items, add the verb "tie" to the hook. You'll then need to set up a short script for that verb, to check if you have both the rod and the hook, and if you have, you print the message that explains the player tying the items together.

The thing is, this will happen every time the player types it in.

So after the event occurs, you'll need to add a line to the script which sets the object (hook) flag to to a string you can easily remember, for example, "tied".

This also means that at the beginning of the script, before you print the message about tying the hook on, you'll need a line which checks the status of the flag.

So it might read something like:

If - object has flag - object "hook - flag "tied"
Print "You've already tied the hook to the rod, and have no wish to untie it".

Else

If - player is carrying object "rod"
Print "You nimbly tie the hook to the end of the rod's line"
Set object flag - object "hook" flag "tied"

Else
Print "You don't have anything you wish to tie the hook to"

I mean that's a pretty hastily explained crappy example, and the same could be achieved with the USE verb and removing the two objects when done and creating a new one called 'fishing rod with hook', but you'll be doing stuff like that all the time.

Hope that inspires you in some way ^_^


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

Support

Forums