Remember the old way of opening the door after picking up the 5 items? Here is the code for the door to refresh your memories.
:state=0,activated=1:state=10
:state=0,activated=2:state=40
:state=0,activated=3:state=70
:state=0,activated=4:state=100
:state=0,activated=5:state=130
:state=10,activated=2:state=11
:state=10,activated=3:state=12
:state=10,activated=4:state=13
:state=10,activated=5:state=14
:state=40,activated=1:state=11
:state=40,activated=3:state=50
:state=40,activated=4:state=60
:state=40,activated=5:state=65
:state=70,activated=1:state=12
:state=70,activated=2:state=50
:state=70,activated=4:state=75
:state=70,activated=5:state=80
:state=100,activated=1:state=13
:state=100,activated=2:state=60
:state=100,activated=3:state=75
:state=100,activated=5:state=110
:state=130,activated=1:state=14
:state=130,activated=2:state=65
:state=130,activated=3:state=80
:state=130,activated=4:state=110
:state=11,activated=3:state=15
:state=11,activated=4:state=16
:state=11,activated=5:state=17
:state=12,activated=2:state=15
:state=12,activated=4:state=19
:state=12,activated=5:state=20
:state=13,activated=2:state=16
:state=13,activated=3:state=19
:state=13,activated=5:state=18
:state=14,activated=2:state=17
:state=14,activated=3:state=20
:state=14,activated=4:state=18
:state=15,activated=4:state=550
:state=15,activated=5:state=540
:state=16,activated=3:state=550
:state=16,activated=5:state=530
:state=17,activated=3:state=540
:state=17,activated=4:state=530
:state=18,activated=2:state=530
:state=18,activated=3:state=520
:state=19,activated=2:state=550
:state=19,activated=5:state=520
:state=20,activated=2:state=540
:state=20,activated=4:state=520
:state=50,activated=1:state=15
:state=50,activated=4:state=67
:state=50,activated=5:state=68
:state=60,activated=1:state=16
:state=60,activated=3:state=67
:state=60,activated=5:state=69
:state=65,activated=1:state=17
:state=65,activated=3:state=68
:state=65,activated=4:state=69
:state=67,activated=1:state=550
:state=67,activated=5:state=510
:state=68,activated=1:state=540
:state=68,activated=4:state=510
:state=69,activated=1:state=530
:state=69,activated=3:state=510
:state=75,activated=1:state=19
:state=75,activated=2:state=67
:state=75,activated=5:state=200
:state=80,activated=1:state=20
:state=80,activated=2:state=68
:state=80,activated=4:state=200
:state=110,activated=1:state=18
:state=110,activated=2:state=69
:state=110,activated=3:state=200
:state=200,activated=1:state=520
:state=200,activated=2:state=510
:state=510,activated=1:state=1000
:state=520,activated=2:state=1000
:state=530,activated=3:state=1000
:state=540,activated=4:state=1000
:state=550,activated=5:state=1000
:state=1000:state=1010,setframe=0,sound=$0
:state=1010:incframe=0
:state=1010,frameatend=0:state=2,coloff
Here is the new code using variables.
;Artificial Intelligence Script
;Header
desc = When Gobal variable #1 = 5 open door
;Triggers
:state=0:globalvar=1
:state=0,varequal=5:state=10
:state=10:state=1,setframe=0,sound=$0
:state=1:incframe=0
:state=1,frameatend=0:state=2,coloff
:state=2:none
;End of Script
;Artificial Intelligence Script
;Header
desc = When player picks up item increment global variable #1 by 1
;Triggers
:state=0:globalvar=1,state=1,hudreset,hudx=50,hudy=90,hudimagefine=gamecoretextpickedupanitem.tga,hudname=itemprompt,hudhide=1,hudmake=display
:state=1,plrdistwithin=50:playertake,incvar=1,coloff,plrsound=audiobankmiscping.wav,hudshow=itemprompt,hudfadeout=itemprompt,state=10
:state=10:rundecal=5,none
;End of Script
You will not be able to use global variable #1 for anything else. Also, you can now easily modify this to have the player pick up any number of items. Hopefully, this will also give everybody a glimpse of how to use global variables. How many global variables one can have is still a question.
There is one other thing I am hoping for and that is all of the global variables are saved when user saves game and not reset. I will be testing that one soon. Otherwise we still won't be able to let the user save the game if the variables are reset.
BTW, this only works starting with v1.09 beta 3.