0 votes
by (160 points)
edited by

So I'm implementing a stats system in my game that allows players to do certain things only when a stat is met.But I want the player to choose their own value for the stats.So I implemented this

[[Intelligence|Arrival][$char.inte to 5]]
[[Popularity|Arrival][$char.popu to 5]]
[[Speech|Arrival][$char.speech to 5]]
[[Toughness|Arrival][$char.toug to 5]]
[[Diplomacy|Arrival][$char.dipo to 5]]

The players would click the link and they would go to a new passage where there are the exact same stat but without the one they clicked and the value of the stats being lower than 4.So far,I've used if statements and to no success and I also tried the different stats to lead to different passages but that would be a lot of passages.So I was wondering if there were any way to implement this.

1 Answer

+2 votes
by (23.6k points)
selected by
 
Best answer

Not entirely sure what you want on your next passage to be. What do you mean when saying "the value of the stats being lower than 4"? Do you mean there will be the same setup but the value added this time will be 4? If that is the case then doing it all within one passage would be easiest.

Let's say you have a setup like this:

<<set $char to {
inte:0,
popu:0,
speech:0,
toug:0,
dipo:0,}>>

<<set $statboost to 5>>

Now you can set up your passage like this:

<<linkreplace "Intelligence">><<set $char.inte += $statboost>><<set $statboost-->>Intelligence: $char.inte<</linkreplace>>
<<linkreplace "Popularity">><<set $char.popu += $statboost>><<set $statboost-->>Popularity: $char.popu<</linkreplace>>
<<linkreplace "Speech">><<set $char.speech += $statboost>><<set $statboost-->>Speech: $char.speech<</linkreplace>>
<<linkreplace "Toughness">><<set $char.toug += $statboost>><<set $statboost-->>Toughness: $char.toug<</linkreplace>>
<<linkreplace "Diplomacy">><<set $char.dipo += $statboost>><<set $statboost-->>Diplomacy: $char.dipo<</linkreplace>>

 

by (160 points)
edited by
Edit:It would seem that the code is working when testing on a seperate test file,but on my project it just shows the $variables back instead of the numbers.I clicked on Intelligence.It show Intelligence:5 on the test file while my main project shows only Intelligence:$char.inte.The numbers are set but they won't appear.
Edit Edit:It would seems that loading from a save caused this trouble.Might be a bug?Anyways thanks for the brilliant answer.And sorry about asking another question but how can I make a link appear after all the variables above have been set.Thanks for answering.
by (23.6k points)

Just add something like the following to all your <<linkreplace>> macros after <<set $statboost -->>:

<<if $statboost lte 0>><<replace "#exit">>[[Continue|nextpassage]]<</replace>><</if>>

Then somewhere in your passage set up a span with the id in question:

<span id="exit"></span>

or

@@#exit;@@

It would look something like:

@@#exit;Choose your Stats:@@

<<nobr>>
<<linkreplace "Intelligence">>
    <<set $char.inte += $statboost>>
    <<set $statboost-->>
    Intelligence: $char.inte
    <<if $statboost lte 0>>
      <<replace "#exit">>
          [[Continue|nextpassage]]
      <</replace>>
    <</if>>
<</linkreplace>>
<</nobr>>


...and so on for all of your links...

Alternatively you could have your link be on the screen the whole time but only work if all stats have been set:

<<nobr>>
<<link "Continue">>
    <<if $statboost lte 0>>
        <<goto "nextpassage">>
    <<else>>
        <<replace "#test" t8n>>
            @@color:red;Please set all your Stats before proceeding@@
        <</replace>>
    <</if>>
<</link>>
@@#test;@@
<</nobr>>

Didn't have time to test any of the above, so be aware of any typos. The principle of how this works should be clear though.

by (44.7k points)

FYI, instead of doing:

<<set $char.inte += $statboost>>
<<set $statboost-->>

You can combine those lines like this:

<<set $char.inte += $statboost-->>

Since the "--" is located at the end of the variable, "$char.inte" will get set to the current value of "$statboost", and then after that the value of "$statboost" will be reduced by 1.

If you did "--$statboost" instead, then "$statboost" would be reduced by 1 first, and then "$char.inte" would get set to that value.

by (160 points)
Thanks for all the help,guys!I really appreciate it.
...