[Doc] How to use Random and While
Posted: Sun Oct 24, 2021 1:34 pm
If, Random and While need to be ended with EndIf, EndRandom and EndWhile respectively, with the correct indentations.
## INCORRECT:
## CORRECT:
'If' is used to check a condition or a set of conditions, if matched then the lines immediately below the 'If' line are executed, if not:
To connect conditions into a set of conditions, '&&' is used for 'and' and '||' is used for 'or'. The square brackets [] are used to group conditions
EXAMPLE:
//this returns true because the first half is true (both its conditions are true) and there's an || in the middle so even when the second half is false, the whole condition set is still true
You can also use the ! sign in front of a bool variable or a condition function to return the opposite of what that variable or function would normally return, for example
// this would match if MyBool is false, vin_VanillaPorn is enabled and the player is not in a relationship
To compare two floats, you can use == (equal), != (not equal), > (larger than), >= (larger than or equal), < (less than), <= (less than or equal)
'While' is similar to 'If', except:
generate 10 temporary actors who come up to say hi to the player one by one
Special Dialogue Choice Condition. A single number as a condition checks for the last choice the player pressed on.
EXAMPLE:
Using Random simply allows you to randomly pick one of the lines between Random and EndRandom to execute
EXAMPLE:
In the above example, the race of the actor generated will be chosen randomly, with each option having an equal 25% chance
## INCORRECT:
Code: Select all
If count > 2
If count > 3
count *= 2
Else
count /= 2
Endif
count += 1
Code: Select all
If count > 2
If count > 3
count *= 2
Else
count /= 2
Endif
count += 1
Endif
'If' is used to check a condition or a set of conditions, if matched then the lines immediately below the 'If' line are executed, if not:
- It jumps to the next 'Elseif' line and check the conditions there.
- If there is no 'Elseif' or if none of the 'Elseif's matched, it jumps to 'Else' and execute the lines below it.
- If there's no 'Else', then nothing is executed
- Between 'If' and 'Endif', there can be as many 'Elseif's as you want, but only one 'Else'.
- One something matches, or if nothing is matched and there's no 'Else', it jumps to the line below 'Endif'
Code: Select all
If 1 > 2 //false so no african person is generated, instead it jumps to the next Elseif
Actor = generatePerson(african)
Elseif 2 < 3 //false again so no eastern european is generated either, it jumps to the next Elseif
Actor = generatePerson(easterneuropean)
Elseif 5 > 2 //true so an east asian is generated, it then ignores the rest and jump after the 'Endif' to dress the actor
Actor = generatePerson(eastasian)
Else //since the above elseif already matched, this Else is ignored
Actor = generatePerson(southasian)
Endif
Actor.dress()
To connect conditions into a set of conditions, '&&' is used for 'and' and '||' is used for 'or'. The square brackets [] are used to group conditions
EXAMPLE:
Code: Select all
If [1 < 2 && 2 < 3] || [6 > 7 && 8 > 10]
//this returns true because the first half is true (both its conditions are true) and there's an || in the middle so even when the second half is false, the whole condition set is still true
You can also use the ! sign in front of a bool variable or a condition function to return the opposite of what that variable or function would normally return, for example
Code: Select all
If !MyBool && isModEnabled(vin_VanillaPorn) && !Player.isDating()
To compare two floats, you can use == (equal), != (not equal), > (larger than), >= (larger than or equal), < (less than), <= (less than or equal)
'While' is similar to 'If', except:
- With 'If', if the conditions are matched, the lines are executed once. With 'While', as long as the conditions remain matched, the lines are executed again and again in a loop until the conditions no longer matched.
- There's no 'Else' or 'Elseif' counterparts for 'While'
- It can cause the game to freeze if you haven't implemented a way for the conditions to become unmatched eventually (indefinite While loop)
generate 10 temporary actors who come up to say hi to the player one by one
Code: Select all
count = 0
While count < 10
Actor = generatePersonTemporary()
Actor.dress()
Actor.show(2)
Actor(Happy):: "Hello, <Player.name>!"
count += 1 //without this line, the loop will continue forever will remain less than 10 forever
Endwhile
Special Dialogue Choice Condition. A single number as a condition checks for the last choice the player pressed on.
EXAMPLE:
Code: Select all
"Invite <CurrentCompanion.name> inside?"
0:: "Yes"
1:: "No"
// not entirely sure why, but an empty line here is crucial - it looks neater anyway
If 0 // instead if just '0', can also be written as 'choice == 0'
Player(Happy):: "Hey, do you want to come in?"
Else
Player(Happy):: "Goodbye darling!"
Endif
Using Random simply allows you to randomly pick one of the lines between Random and EndRandom to execute
EXAMPLE:
Code: Select all
Random
Actor = generatePerson(african)
Actor = generatePerson(eastasian)
Actor = generatePerson(easterneuropean)
Actor = generatePerson(southasian)
EndRandom