ChoicescriptIDE / ChoicescriptIDE/main

Warn on use of rand before a page break

Open
#114 0 comments 0 reactions 0 assignees View on GitHub
backlog feature validation-ls
Dominant language
JavaScript
Stars
36
Forks
8
PR merge metrics
No merged PRs in 30d

Description

The way that the stats menu is implemented in ChoiceScript means that the main scene code is actually re-executed when you leave the stats screen. In most circumstances code will be deterministic and re-execute as expected. However, if you're using the rand command, then things can get tricky.

Take the following example:

```
*create player_cash 10
*temp rand_var 0
*rand rand_var 1 100
You won ${rand_var} gold!
*set player_cash + rand_var
You now have ${player_cash} gold.
*page_break
```

Here we generate a random amount of gold, display the value to the player, and add it to their total gold. Simple enough.
Now, what if the player decides to visit the stats screen at this point? The code will re-execute when they leave it, and you guessed it, we might end up with a different random value (and thus total gold value).

Needless to say this can open the game up to abuse. The solution is to "roll" the random value a page (or more) before you need it. I think it should be possible for us to issue a validation warning on any usage of a *rand(ed) variable that occurs before a page_break(ing) command (page_break, choice, finish), which should help authors avoid this sort of error more often.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.