Character stats

Im doing a character creation with a radiobutton menu.

<label><<radiobutton "$background" "Valedictorian">><b>Highschool</b></label><br>
You were top of your class. Voted most likely to succeed. Class Valedictorian. +10 Int +5 Charm <<set $intelligence += 10>><<set $charisma += 5>><br>
<label><<radiobutton "$background" "Star Athlete">><b>Jock</b></label><br>
You were the star athlete. You won your school many state championships. +10 Stamina +5 Strength <<set $stamina += 10>><<set $strength += 5>><br>
<label><<radiobutton "$background" "Popular Kid">><b>Popular</b></label><br>You were the most popular kid in class. Everyone loved you and wanted to be around you. +15 Looks +10 Charm <<set $looks += 15>><<set $charisma += 10>>

I need to mpt have it add all the stats at once, only the one that is chosen. What Im wondering is, instead of what I have there if i need to use if statments instead?

Something like:

<<if $background is "Valedictorian">>
     <<set $intelligence += 10>>
     <<set $charisma += 5>>
<<elseif $background is "Star Athlete">>
     <<set $stamina += 10>>
    <<set $strength += 5>>
<<else if $background is "Popular">
     <<set $looks += 15>>
    <<set $charisma += 10>>
<</if>>
<</if>>
<</if>>

would that keep it from adding all the stats to the character and only the one that is chosen?

If you do it like that, the players will get all the stats when coming into the passage.

Since you can’t have a conditional statement inside a radio button:

<label><<radiobutton "$background" "Valedictorian">><b>Highschool</b></label>
<label><<radiobutton "$background" "Star Athlete">><b>Jock</b></label><br>
<label><<radiobutton "$background" "Popular Kid">><b>Popular</b></label>

<<link [[Confirm|Next passage]]>>
 <<if $background is "Valedictorian">>
     <<set $intelligence += 10>>
     <<set $charisma += 5>>
 <<elseif $background is "Star Athlete">>
     <<set $stamina += 10>>
     <<set $strength += 5>>
  <<else>>
     <<set $looks += 15>>
     <<set $charisma += 10>>
  <</if>>
<</link>>

Would this work with a popup rather than going to another passage? as there are other thngs I want to add to it as well for the character before its finished.

If the radiobutton is in the popup, yea it’s fine.

<<link  "Confirm">>
    /* You code for the variable */
   <<run Dialog.close()>>
<</link>>

awesome. Thanks. you’re helping me learn a lot about coding and things. This game may turn out pretty good in the end.

1 Like

I have a whole character creator template here if you’re interested. Less skills/stats focused, more on how the interactive macros can be used.

oh nice!! Thanks!

So Im not sure what im supposed to put in here.

<<link  "Confirm">>
    /* You code for the variable */
   <<run Dialog.close()>>
<</link>>

I tried a few things and when I click confirm nothing changes.
is it supposed to be

<<set $background to "radiobutton choice">>

Or the if statment with the stat variables. I tried both and nothing changed just closed out the popup with no added stat or background

Closing a popup doesn’t refresh the page by default, but it probably worked. If you want the page to be refreshed could add this right before the Dialog close

<<run state.display(state.active.title, null)>>

That worked perfect Thanks! Now is there a way to kill that link so they cant go back into it once it is selected? I tried once before with

<<if $vis is true>>

<<if hasVisited("background")>>



<</if>>

but that doesn’t seem to work it just makes the link disappear before its used no matter what i do with it.

Don’t make a story variable for it just wrap the link code in:

<<if visited() < 2>>\

<</if>>\

which will limit it to appearing only the first visit. hasVisited is no good in instances like this.

Perfect, Thank you very much. Its coming along nicely.

That’s an old old way of doing

<<goto `passage()`>>

:smiley:

Or, apples to apples:

<<run Engine.play(passage())>>

But, if you’re doing that, then just use <<goto>> as @Hituro showed above.

Also as @Hituro mentioned, the code shown by @jeb019 has been deprecated for many years now and has been removed from the next version of SugarCube (v2.37.0). You really don’t want to be using it.

Is there a way to make an image link as a popup?

[img[$bag|DFimages\bag.png][inventory]]

<<link "<img src='URL'>">>/* Popup Dialog Code*/<</link>>

awesome. thank you

Something about this is leaving a broken image
<<link "<img src='DFimages\bag.png'>">><<popup 'inventory'>><</link>>

Network path separators are always forward slashes (/), regardless of what your local filesystem uses. Browsers will generally fix that for you, but you shouldn’t count on it.

Additionally, the backslash (\) is commonly an escape metacharacter in programming languages, which could be biting you here.

Anyway. Try using the forward slash. E.g.

<<link "<img src='DFimages/bag.png'>">>
    <<popup 'inventory'>>
<</link>>

 
Beyond that, if you’re testing from Twine, you’ll also need to publish to file and ensure that HTML file is relative to your DFimages directory, because Twine’s testing builds are created in a temporary location on disk rather than wherever your images are.

yup that was what did it, Thanks. Its always little things like that that i tend to miss