Can you add an integer and a string?

I’m having problems with choicescript(as you probably guessed) and here is my code:

*create pgsfnd 0
*create pgsfndttl pgsfnd + “/20”

Look, I’m trying to get it so that if ‘pgsfnd = 1’ then pgsfndttl is ‘1/20’. But whenever I start up my story it says: 'line 25: Invalid create instruction, value must be a a number, true/false, or a quoted string: pgsfndttl pgsfnd + “/20” ’

What am I doing wrong?

*create pgsfnd 0
*create pgsfndttl 0
*if pgsfnd = 1
*set pgsfndttl (pgsfnd div 20)

Unless you want the pgsfndttl to be a string then just
*create pgsfnd 0
*create pgsfndttl “”
*if pgsfnd = 1
*set pgsfndttl “1/20”

If you were looking for a numeric variable, e.g. pgsfnd 16/20 = .75, then you want

*create pgsfnd 0
*create pgsfndttl pgsfnd/20

If you wanted a string using the two, which I finally understand is what you’re going at, use an ampersand, not an addition symbol, when joining string variables. As such…

*create pgsfnd 0
*create pgsfndttl pgsfnd&"/20"

I hope I clarified that for you!

EDIT: If you ever want to just check/test small bits of code without having to play through your story, use CJW’s Online CS Tester. It’s kinda invaluable.

I forgot div is not CS. pgsfnd/20 works as Caddmuss said.

Now it gives me 'Invalid create instruction, value must be a a number, true/false, or a quoted string: pgsfndttl pgsfnd&"/20" ’

Thanks for the link BTW

@MetaKraid
You can’t reference another variable when using *create. You’ll have to either create pgsfndttl with a value of 0 and *set it on the next line, or… actually I’m not sure what you’re trying to do with that “/20”. Is that supposed to stay a string of text or did you want to divide something by 20?

So should I do '*set pgsfndttl pgsfnd&"/20" ’ at the stats page? And I want it to read ‘0/20’

If I understand you right,

*create pgsfndttl 20
*create pgsfnd 0

<—Something happens during the game —>
*set pgsfnd +1 or whatever value relevant to the story

In the stat file should be something like

{pgsfnd} / {pgsfndttl}

without *stat_chart preceding. Basically it just prints your two variables onto the screen.

If you don’t need it in the main game, then yes, you can *set that in the stats page.
Alternatively, this would also work:

*create pgsfnd 0
*create pgsfnd "/20"

${pgsfnd}${pgsfndttl}

Of course, don’t put the create commands in the stats page.

Edit: Or, FcA’s method might suit your purposes better, depending on the application of the “/20”. :slight_smile:

I’m a bit confused. How do I display ‘{pgsfnd} / {pgsfndttl}’ on the stats page?

If you wanted to put it in a *stat_chart, here’s what I might do…

choicescript_stats.txt

*temp pgsfndttl pgsfnd&"/20"

*stat_chart
  blahotherstatsblah
  text pgsfndttl Pages Found

That way you don’t have that extra pgsfndttl all the time and it automatically sets up each time they check their stats. All you ever have to *set is the pgsfnd, when a page is found.

Edit: I’m just assuming pgsfnd means you’ve… found a… page.

Thanks, it works!