The problem comes because no matter what I try I keep getting invalid syntax at the start of the second if statement
[...]
Code:
File "game/Scripts/Database/test.rpy", line 19, in script
if $levelselect = 1:
SyntaxError: invalid syntax (game/Scripts/Database/test.rpy, line 19)
I'm not sure what else to try for anymore I would any help to get it working and jumping to the labels based on the random number.
What to try is just to be careful when you write your code. Coding languages have a absolutely strict syntax and grammar. Therefore, unlike "speaking language", a small error will totally change the meaning of what you wrote ; generally leading to a totally none understandable sentence.
The errors (yes, there's two) are explicitly pointed out and correctly described (which don't always happen with Ren'py). But, more important, only one of the errors is present in the example you gave.
So :
- Remove the bogus
$
before the variable name. The character is used to introduce an inline python code, not to prefix a variable ; Python do not prefix variables.
- Replace the assignation operator (
=
) by the equality operator (==
).
This said :
init python:
import random
This isn't needed and shouldn't be used. The random module is natively available through
renpy.random
witch provide the advantage to be Ren'py compliant.
label level1pick:
_random.randit (1,5)
_$levelselect = random.randint
__ if levelselect = 1:
___ jump .locallabel1
__elif levelselect = 2:
___ jump .locallabel2
__elif levelselect = 3:
___ jump .locallabel3
__ elif levelselect = 4:
___ jump .locallabel4
__ else
___ jump .locallabel5
The first line have a syntax error ("randit" in place of "randi
nt") and don't assign it's value.
The second line assign the value of the
randint
method, not the result of a randomized value ;
more regarding this error and the use of ()
.
Anyway, using a combination between the
expression
property and
random.choice
is better here :
Code:
label level1pick:
jump expression renpy.random.choice( [ "choice 1", "choice 2", "choice 3" ] )
Edit:
Also, regarding my "be careful", you need to be way more strict when you write.
Look at your message, you used the
code
tag to format the traceback, but despite its obvious name, didn't thought about its effect when formating the code example you gave. This kind of inattention isn't compatible with code writing.