Non-threaded

Forums » Advanced Editor Forum » Read Thread

Get help from the experts on variables, scripts, items, and other scary things.

Changing variables based on other variable values

2 years ago
Forgive me if something similar was already posted, feel free to link me to that thread if so. So I'm writing a game in which stats can be increased through training, but how much said stat is increased depends on the level of your training center. The amount of money it costs to train that stat also depends on that training center level. So let's say you want to increase your Speed stat - at training center level 1, it would cost $25 a "session" (session being the link to train being clicked) and increase your Speed stat by 2 points. But if I upgrade my training center to level 2, it would then cost $50 a session and raise your stat by 5 points. At levels 3 and 4, the stat increases via multiplication (2x and 3x). I do know how to change variable values through links, but I haven't quite figured out how to go about changing variables based on the value of another variable. My assumption is some sort of If/Then statement with the stat/money variables and the training center level variable, but I haven't done much scripting in CYS games so I'm not entirely sure how to format that in a link script or some other kind of script as needed.

Changing variables based on other variable values

2 years ago
You’re right with the if then statements, there’s definitely some articles on scripting.

Changing variables based on other variable values

2 years ago
There are two main ways I'd do this.

Either have everything in one link script.

IF %AREA = 1 THEN %SPEED := %SPEED + 2
IF %AREA = 2 THEN %SPEED := %SPEED + 4
IF %AREA = 3 THEN %SPEED := %SPEED + 6

(Or use ELSE to be more logical)

IF %AREA = 1 THEN %SPEED := %SPEED + 2 ELSE
IF %AREA = 2 THEN %SPEED := %SPEED + 4 ELSE
IF %AREA = 3 THEN %SPEED := %SPEED + 6

(Change numbers to be what you actually want).

Otherwise I'd have separate links that are visible based on the area level.

Link 1:
Restriction: %AREA = 1
Link Script / Modify Variables: %Speed := %Speed + 2

Link 2:
Restriction: %AREA = 2
Link Script / Modify Variables: %Speed := %Speed + 4

Link 3:
Restriction: %AREA = 3
Link Script / Modify Variables: %Speed := %Speed + 6



However, since you'd also want logic for the price, I think the second option is easier to implement.

You'd add an extra restriction:
%MONEY >= 25 (or whatever the minimum they must have is).

Then in the Link Script or Modify Variables section, you'd subtract the price from the money as well:
%MONEY := %MONEY - 25



Oh, also, under storygame properties, you can change editor features (link towards the bottom).

Set everything to advanced so you can see all the options. (Might not be necessary for this, I'm not sure, and am too lazy to check).

Changing variables based on other variable values

2 years ago
I'm not sure if everything advanced is necessary but I've had the editor options set as such anyway because I don't really care to check. Would there be a way to integrate the monetary restriction into the link script along with the other code for the stats or would I just have to make different links like you mentioned?

Changing variables based on other variable values

2 years ago
You need advanced scripting turned on in order to use global scripts. I can't do exact examples right now but you're on the right track. Just set up all your math as a big global page script, then the only thing you need to modify during the game itself is the training center levels in link scripts whenever the player changes them.

Link restrictions are a different thing, those are the ones on the little stop sign icon. They have to be set up on the individual links because they're just controlling whether it shows up or not or if it's greyed out or what. You need them for any kind of money system so that it knows to disable them when the player doesn't have enough, but restrictions aren't difficult to set up, it's all just clicking boxes.

Changing variables based on other variable values

2 years ago
Yeah I've played around with the restrictions before, I was just curious if there was a link/global script alternative to make things simpler (to me at least). The second option that Zake mentioned also works totally fine so no issues with that if there isn't an alternative. It all does the same thing in a simple way anyway.

Changing variables based on other variable values

2 years ago
Well, if you don't disable the links somehow, you'd want to redirect to another page if they can't pay for the choice they made.

IF %MONEY < 25 THEN $DEST := @P10

(That redirects to page id 10 if the money variable is less than 25).


So:

IF %AREA = 1 THEN
IF %MONEY < 25 THEN
$DEST := @P17 ELSE
BEGIN
%SPEED := %SPEED + 2
%MONEY := %MONEY - 25
END

This means that you go to the link destination if you have enough money, otherwise you are redirected to Page 17.

Let me know if it works, since I didn't test this one as much.

Changing variables based on other variable values

2 years ago
Yes. On the Link Restrictions page, it will list all your defined variables. You can simply select greater than in the type column for more than one variable.