# Strings and Numbers in Choicescript

**URL:** <https://forum.choiceofgames.com/t/strings-and-numbers-in-choicescript/82535>\
**Category:** Game Development\
**Created:** [July 9, 2020, 1:21am UTC](https://forum.choiceofgames.com/t/strings-and-numbers-in-choicescript/82535 "2020-07-09T01:21:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![autumnchen](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/autumnchen/32/136343_2.png) [@autumnchen](https://forum.choiceofgames.com/u/autumnchen)\
**Post date:** [July 9, 2020, 1:21am UTC](https://forum.choiceofgames.com/t/strings-and-numbers-in-choicescript/82535/1 "2020-07-09T01:21:32Z")

</div>

This is kind of random and probably old news, but I just discovered that strings containing numbers can essentially be used as numbers in choicescript. I was interested in this because I was storing a list of integers as a string (for an equipment system), and I wondered if I would have to create a str\_to\_int function. Thankfully that’s not necessary.

```
*temp a 123
*temp b "2"
*set a - b
a: ${a} ${a + b} ${b + a} ${a*b} ${b*a}

```

This prints `a: 121 123 123 242 242 `.

```
*set a "123"
*if (a = 123)
  a
*if (1 = "1")
  b

```

This prints `a b`, which means that the string `"123"` is equal to the number `123`. Interestingly this is also what happens in Javascript. However the previous behavior is different from javascript: `"121" + 2` would give `"1212"` in js.

“Numeric strings” can also be used as indices:

```
*temp array_1 1
*temp array_2 2
*temp array_3 3
*temp index "2"
${array[index]} 

```

This prints `2`.

It goes the other way, too. Numbers can be concatenated to strings.

```
*temp d "abc_"&1
d: ${d}

```

This prints `d: abc_1`.

---

<div class="post-metadata">

**Author:** ![choicehacker](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/choicehacker/32/127936_2.png) [@choicehacker](https://forum.choiceofgames.com/u/choicehacker)\
**Post date:** [July 9, 2020, 1:51am UTC](https://forum.choiceofgames.com/t/strings-and-numbers-in-choicescript/82535/2 "2020-07-09T01:51:48Z")

</div>

Thanks for sharing. I use this feature as a way to enter negative numbers.

\*set var -1

will decrease the variable. To set it to -1, you can do

\*set var "-1”

Another way would be

\*set var (0 - 1)
