I'd like some skills to be a count rather than a percentage, but I don't want to repeat code

I’m having trouble with creating certain skills as a count rather than a percentage.

My current code works, I’m not getting any error messages, but I’d like to clean it up a bit if I can.

Here’s what the skills look like on the stats page:

skills1

The trouble comes from those identifiers: “knowledgeable”, “dabbling”, etc. I have to repeat the same lines of code, three times, in order for them to work. Is there a way to condense them so I only have to do it once?

My code looks like this:

*label skillDesc_lang
*if lang >= 10
    (Expert)
    *return
*elseif lang >= 8
    (Highly Skilled)
    *return
*elseif lang >= 6
    (Skilled)
    *return
*elseif lang >= 4
    (Knowledgeable)
    *return
*elseif lang >= 1
    (Dabbling)
    *return
*else
    (Unfamiliar)
    *return

That’s the code for languages, and I’ve copy/pasted it again for history and again for technology. It would be nice if I only had to do it once.

I saw something like this in Choice of Magics, so I went and did some code diving. It looks like the author used params, but when I tried to mimic their coding, I couldn’t get it to work. Any suggestions?

Try this:

I am @{lang dabbling|dabbling|dabbling|knowledgeable|knowledgeable|skilled|skilled|highly skilled|highly skilled|an expert|an expert} at languages.

A bit wonky, and doesn’t super solve the problem, but it’s at least an alternative if you don’t like the look of what you’ve already got.

5 Likes

Create a file called skills with that that bit of code in it.

Then any time you want to use that code simply put

*gosub_scene skills

That will do exactly what you want it to do but only need the code written once.

4 Likes

Take a look at how params work for subroutines: Params | ChoiceScript Wiki | Fandom

Here is a complete working example of how it might work in your case (all of the code is in a single scene file. If you want to access it from multiple scene files, you can use *gosub_scene instead)

*temp language 5
*temp history 3
*temp technology 1

Language: ${language} 
*gosub skillDesc language
*line_break
History: ${history} 
*gosub skillDesc history
*line_break
tech: ${technology} 
*gosub skillDesc technology
*line_break
*finish

*label skillDesc
*params skill
*if (skill) >= 10
    (Expert)
    *return
*elseif (skill) >= 8
    (Highly Skilled)
    *return
*elseif (skill) >= 6
    (Skilled)
    *return
*elseif (skill) >= 4
    (Knowledgeable)
    *return
*elseif (skill) >= 1
    (Dabbling)
    *return
*else
    (Unfamiliar)
    *return
8 Likes

Omg thank you quartz!!! This is exactly what I was looking for. I’ve struggled with this for an annoyingly long time. Thank you to everyone who responded; I appreciate the help, truly.

2 Likes

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.