You only need the variable name with "dimvar". You would use the numerical value with the variable when using commands such as "setvar".
For example, I made a traversing levels demo where you go into the 2nd level and it splits into three- Level 3 holds a key, level 4 holds nothing, and level 5 is the locked door which requires the key from level 3. In my level 3, I have the key appear script as follows:
;Artificial Intelligence Script
;Header
desc = Instant On
;Triggers
:state=0:dimvar=key
:state=0:state=1
:state=1,varequal=key 0:state=5
:state=1,varequal=key 1:state=10
:state=5:setalphafade=100,runfpidefault=1
:state=10:destroy
;End of Script
Each time I enter level 3, if I have already picked up the key once, it checks the variable "key" and if the value is 0, it runs the default script assigned; if the value is 1, it destroys the key.
Next is the pickup script for the key.
;Artificial Intelligence Script
;Header
desc = Pickup Key
;Triggers
:state=0:hudreset,hudx=50,hudy=90,hudimagefine=gamecore\text\pickedupakey.tga,hudname=keyprompt,hudhide=1,hudmake=display,state=10
:state=10,plrdistwithin=40:state=1,playertake,coloff,plrsound=audiobank\misc\ping.wav,hudshow=keyprompt,hudfadeout=keyprompt
:state=1:dimvar=key,state=2
:state=2:setvar=key 1,state=3
:state=3:none
;End of Script
When I approach the key and pick it up, the variable "key" is called (dimvar=key) and then I set the value to 1. So when I exit level 3 back to 2 and return to 3, the key will not appear (as outlined above).
Now we look at the locked door in level 5.
;Artificial Intelligence Script
;Header
desc = Key Door (Open 'With Key' and Close)
;Triggers
:state=0:hudreset,hudx=50,hudy=90,hudimagefine=gamecore\text\lockeddoor.tga,hudname=keydoorprompt,hudhide=1,hudmake=display
:state=0:dimvar=key
:state=0:state=1
:state=1,plrdistwithin=60:hudshow=keydoorprompt,hudfadeout=keydoorprompt
:state=1,plrdistwithin=60,varequal=key 1,plrusingaction=1:state=2,setframe=0,sound=$0
:state=1,plrdistwithin=60,varequal=key 0,plrusingaction=1:state=5,etimerstart
:state=2:incframe=0
:state=2,frameatend=0:state=3,coloff
:state=3,plrdistfurther=60:state=4,sound=$1,colon
:state=4:decframe=0
:state=4,frameatstart=0:state=1,setframe=0
:state=5,etimergreater=2000:state=0
;End of Script
As you can see, if I went from level 2 to 5, the door will not unlock as it checks the variable "key". If the value equals 1, I can unlock it; if not, the door remains locked.
I have a video showing this. You start in level 1, go to 5 to discover the locked door, back to 2, to level 3 for the key, back to 5. I even go back to 3 just to show the key does not appear because of the variable value. Hopefully it will help you.
There's no problem that can't be solved without applying a little scripting.