Hi
Im making a house with a dwemer fireplace. Theres a dwarven crank nearby. The fire is off, but when you turn the crank, the fire turns on.
This is my first time using global scripts, and I can't quite crack this problem. I was hoping someone here might shed some light? Im using OpenMW to test.
The first script is attached to the flame itself, and seems to work. By editing the local variable, the fire does indeed appear or disappear.
Begin USaS_StoveFlame
short USaSGlobalFlame
if ( USaSGlobalFlame == 0 )
USaS_StoveFlame->disable
;Flame off
endif
if ( USaSGlobalFlame == 1 )
USaS_StoveFlame->enable
;Flame on
endif
End USaS_StoveFlame
The second is attached to the crank. I mustve tried a dozen different permutations of this script:
begin USAS_StoveScript
float angle
short USaSGlobalFlame
if ( menumode == 1 )
return
endif
if ( OnActivate == 0)
return
endif
if ( OnActivate == 1)
if ( USaSGlobalFlame == 0 )
PlaySound "Disarm Trap Fail"
set USaSGlobalFlame to 1
else
PlaySound "Disarm Trap Fail"
set USaSGlobalFlame to 0
endif
return
endif
End USAS_StoveScript
I cannot work why, when i activate the crank, the flame does not appear. It makes the use sound only once.
Scripting a switch to turn on a light
Re: Scripting a switch to turn on a light
If the variable is a global, it doesn't need to be declared locally.
-
- Posts: 10
- Joined: 10 Dec 2019, 22:56
Re: Scripting a switch to turn on a light
Im sorry to sound like an idiot, but could you tell me which part of the script is declaring the USaSGlobalFlame variable locally?
As I understand global variables (and I dont), it should work like so:
My global variable is USaSGlobalFlame, which is just a number. We want it to be either 1 or 0, depending on whether the fire is on or not. It is a short global.
I have two objects. One is the crank (USaS_StoveCrank), the other is the fire (USaS_StoveFire).
The script attached to the crank makes a noise and changes the global variable when you turn it.
The script attached to the fire checks the variable, and either enables or disables it accordingly.
The problem is... they dont work. So I read some GhanBuriGhan, and I did some poking with different phrasing and methods (messageOn etc)
As I stand there, illuminated by the fire in the cell next furiously clicking my crank, i think, hey, what happens if we type into the console:
set USaSGlobalFlame to 0
nothing happens in .46. Or the RCs. Vanilla just throws a CTD.
why cant i extinguish this fire? I clearly have a misunderstanding of global variables.
As I understand global variables (and I dont), it should work like so:
My global variable is USaSGlobalFlame, which is just a number. We want it to be either 1 or 0, depending on whether the fire is on or not. It is a short global.
I have two objects. One is the crank (USaS_StoveCrank), the other is the fire (USaS_StoveFire).
The script attached to the crank makes a noise and changes the global variable when you turn it.
The script attached to the fire checks the variable, and either enables or disables it accordingly.
The problem is... they dont work. So I read some GhanBuriGhan, and I did some poking with different phrasing and methods (messageOn etc)
As I stand there, illuminated by the fire in the cell next furiously clicking my crank, i think, hey, what happens if we type into the console:
set USaSGlobalFlame to 0
nothing happens in .46. Or the RCs. Vanilla just throws a CTD.
why cant i extinguish this fire? I clearly have a misunderstanding of global variables.
Re: Scripting a switch to turn on a light
The lines:could you tell me which part of the script is declaring the USaSGlobalFlame variable locally?
Code: Select all
short USaSGlobalFlame
I am a bit rusty, but I do not think:
Code: Select all
if ( menumode == 1 )
return
endif
-
- Posts: 10
- Joined: 10 Dec 2019, 22:56
Re: Scripting a switch to turn on a light
Thankyou both for your help
This one is making my brain itch. I'll post my result when I work it out, which doesnt feel like soon.
This oven will not defeat me.
This one is making my brain itch. I'll post my result when I work it out, which doesnt feel like soon.
This oven will not defeat me.
-
- Posts: 10
- Joined: 10 Dec 2019, 22:56
Re: Scripting a switch to turn on a light (Solved)
I did it!
Okay, now Ive wrapped my head around it, I totally understand you both. Changing my approach to writing a script helps as well.
Instead of cobbling together paragraphs of existing code, just start small with function you know, and expand it.
For example, a crank that when activated, adds a light. 2 objects, 3 scripts (2 local, 1 global)
-------------------------------------------------------------------------
First script
begin aaa_light
;applied to the light
if ( aaa_global_crank == 0 )
enable
endif
if ( aaa_global_crank_crank == 1 )
disable
endif
end aaa_light
Second Script
begin aaa_crank
;applied to the crank
short messageOn
if ( MenuMode == 1 )
return
endif
if ( OnActivate == 1 )
set aaa_global_crank to 1
return
endif
end aaa_crank
-------------------------------------------------------------------------
You can then add the extra features one at a time, like turning off them off again.
Knowing what shorting is and does, helped me not use it when it was just getting in the way.
Thankyou!
Okay, now Ive wrapped my head around it, I totally understand you both. Changing my approach to writing a script helps as well.
Instead of cobbling together paragraphs of existing code, just start small with function you know, and expand it.
For example, a crank that when activated, adds a light. 2 objects, 3 scripts (2 local, 1 global)
-------------------------------------------------------------------------
First script
begin aaa_light
;applied to the light
if ( aaa_global_crank == 0 )
enable
endif
if ( aaa_global_crank_crank == 1 )
disable
endif
end aaa_light
Second Script
begin aaa_crank
;applied to the crank
short messageOn
if ( MenuMode == 1 )
return
endif
if ( OnActivate == 1 )
set aaa_global_crank to 1
return
endif
end aaa_crank
-------------------------------------------------------------------------
You can then add the extra features one at a time, like turning off them off again.
Knowing what shorting is and does, helped me not use it when it was just getting in the way.
Thankyou!