I found this thread from Mr Game with a very interesting question about using variables for a combination puzzle:
http://forum.thegamecreators.com/?m=forum_view&t=166053&b=23
This kind of puzzle gives the player only 2 choices (left/ reight) which can get combined to a combination like: 3 left, 2 right, 1 left.
Ingame this can be done with sundials (like MrGame did it) or buttons or switches or the keyboard.
My idea for a easy solution was to write the combination as a binary code like 000110.
"0" would stand for a "left" and "1" for a "right" choice.
To be able to use that "code" in a script you have to make a decimal number out of it:
In my example above the code "3 left, 2 right, 1 left" is: "000110"
To get a dezimal number you have to delete all zero at the left side of the code.
So the code is : 110
What does the script do to compare the player input with the combination?
It adds, depending of the current number of player inputs a value to a variable and after 6 inputs it compares the value of the variable with the wanted combination.
Example:
The used variable starts with a value of 0.
The players first choice is "right" -> script adds 100000 to the variable.
Second choice is "left" -> nothing happens.
Third choice is "right" -> script adds 1000 to the variable.
Choice 4-6 is "left" -> nothing happens.
So the variable has the value 101000 after 6 player inputs.
The wanted combination was 110. So the players input was incorrect.
Why this way?
Because if you want to use the script for more than one puzzle the only thing to change is the combination.
No need the change lots of lines of code.
The script is not meant for drag and drop usage because i used rawtext as placeholder for other actions like rotation, or switch animation etc..
For testing it can get used as is (works only with vanilla FPSC v.1.16).
The defined keys for "left" and "right" are the N and M keys.
The script:
;Artificial Intelligence Script
;Header
desc = dial, combination: 3 left, 1 right, 1left, 1 right = 000101 = 101 as dezimal number (see state=70)
;Triggers
:state=0:localvar=0,setvar=0,state=1
:state=1:localvar=1,setvar=0,state=2
:state=2:activate=0,state=10
:state=10:fpgcrawtextsize=24,fpgcrawtextfont=verdana
:state=10:fpgcrawtextr=255,fpgcrawtextg=255,fpgcrawtextb=255
:state=10:fpgcrawtextx=50,fpgcrawtexty=70
:state=10:state=20
:state=20:localvar=1
:state=20,plrdistfurther=120,vargreater=0:state=0
:state=20,plrdistwithin=80,scancodekeypressed=49:state=30
:state=20,plrdistwithin=80,scancodekeypressed=50:state=35
:state=30,scancodekeypressed=0:activate=0,state=40,fpgcrawtext=<--
:state=35,scancodekeypressed=0:activate=1,state=40,fpgcrawtext=-->
:state=40:localvar=1
:state=40:incvar=1,state=50
:state=50,varequal=1:state=60
:state=50,varequal=2:state=61
:state=50,varequal=3:state=62
:state=50,varequal=4:state=63
:state=50,varequal=5:state=64
:state=50,varequal=6:state=65
:state=60:localvar=0
:state=60,activated=1:incvar=100000,state=20
:state=60,activated=0:state=20
:state=61:localvar=0
:state=61,activated=1:incvar=10000,state=20
:state=61,activated=0:state=20
:state=62:localvar=0
:state=62,activated=1:incvar=1000,state=20
:state=62,activated=0:state=20
:state=63:localvar=0
:state=63,activated=1:incvar=100,state=20
:state=63,activated=0:state=20
:state=64:localvar=0
:state=64,activated=1:incvar=10,state=20
:state=64,activated=0:state=20
:state=65:localvar=0
:state=65,activated=1:incvar=1,state=70
:state=65,activated=0:state=70
:state=70:localvar=0
:state=70,varequal=101:state=0,fpgcrawtext=CORRECT COMBINATION
:state=70,varnotequal=101:state=0,fpgcrawtext=WRONG COMBINATION
;End of Script
As you can see the only thing to do to change the wanted combination is to set a other value in 2 lines in state=70.
Commented version:
;Artificial Intelligence Script
;Header
desc = dial, combination: 3 left, 1 right, 1left, 1 right = 000101 = 101 as dezimal number (see state=70)
;Triggers
;---------------------------------------------------------
; reset all variables
;------------------------------
:state=0:localvar=0,setvar=0,state=1
:state=1:localvar=1,setvar=0,state=2
:state=2:activate=0,state=10
;---------------------------------------------------------
; rawtext setup
;------------------------------
:state=10:fpgcrawtextsize=24,fpgcrawtextfont=verdana
:state=10:fpgcrawtextr=255,fpgcrawtextg=255,fpgcrawtextb=255
:state=10:fpgcrawtextx=50,fpgcrawtexty=70
:state=10:state=20
;---------------------------------------------------------
; if plr leaves the zone reset the script (state=0)
; check which key the plr presses while he is close to the entity
;-------------------------------
:state=20:localvar=1
:state=20,plrdistfurther=120,vargreater=0:state=0
:state=20,plrdistwithin=80,scancodekeypressed=49:state=30
:state=20,plrdistwithin=80,scancodekeypressed=50:state=35
;---------------------------------------------------------
; plr has pressed a key --> "activate" gets set to plrs choice (left=0/ right =1)
;-------------------------------
:state=30,scancodekeypressed=0:activate=0,state=40,fpgcrawtext=<--
:state=35,scancodekeypressed=0:activate=1,state=40,fpgcrawtext=-->
;---------------------------------------------------------
; set variable #1 to number of plr inputs by increasing the value by 1
;-------------------------------
:state=40:localvar=1
:state=40:incvar=1,state=50
;---------------------------------------------------------
; go to states 60-65 depending on the current number of plr inputs
;-------------------------------
:state=50,varequal=1:state=60
:state=50,varequal=2:state=61
:state=50,varequal=3:state=62
:state=50,varequal=4:state=63
:state=50,varequal=5:state=64
:state=50,varequal=6:state=65
;---------------------------------------------------------
; states 60-65
; when plr choice was "left" nothing happens
; when plr choice was "right" a defined value gets added to variable #0
;-------------------------------
:state=60:localvar=0
:state=60,activated=1:incvar=100000,state=20
:state=60,activated=0:state=20
:state=61:localvar=0
:state=61,activated=1:incvar=10000,state=20
:state=61,activated=0:state=20
:state=62:localvar=0
:state=62,activated=1:incvar=1000,state=20
:state=62,activated=0:state=20
:state=63:localvar=0
:state=63,activated=1:incvar=100,state=20
:state=63,activated=0:state=20
:state=64:localvar=0
:state=64,activated=1:incvar=10,state=20
:state=64,activated=0:state=20
:state=65:localvar=0
:state=65,activated=1:incvar=1,state=70
:state=65,activated=0:state=70
;------------------------------------------------------
; plr made 6 choices
; variable #0 gets compared with defined "code"
;------------------------------
:state=70:localvar=0
:state=70,varequal=101:state=0,fpgcrawtext=CORRECT COMBINATION
:state=70,varnotequal=101:state=0,fpgcrawtext=WRONG COMBINATION
;End of Script
Hope my text is understandable...i am not a native english speaker.