Scripts: Enable when disabled Disable when enabled

Post » Wed May 02, 2012 4:30 pm

I'm trying to make some kind of a riddle. Shortly, we have 5 lights and 5 buttons. Each button turns off the light when it's enabled or turns on when disabled. The same rule applies to the surroundings lights on the left and right side, so, for a better view:
We have five lights on:
[x][x][x][x][x]
Then we press second button and we are turning off second light and surrounding ones (because all were enabled)
[ ][ ][ ][x][x]
Then we press third button and we turning on two lights (due to disabled status) and off only one (due to enabled status).
[x][x][x][ ][x]

Ok, so this is how it works ... in my mind.

I've made two scripts. The first one was pinned to every light:

begin cc_mar_s_litestatusshort stateif ( GetDisabled == 1 )	set state to 0endifif ( GetDisabled == 0 )	set state to 1endifend

The second script was added to button and it looks as follows:

begin cc_mar_s_litesbtn2if ( OnActivate == 1 )PlaySound, "Torch Out"	if ( "cc_mar_lite1"->GetDisabled == 0 )		Disable	else		Enable	endifendifif ( OnActivate == 1 )PlaySound, "Torch Out"	if ( "cc_mar_lite2"->GetDisabled == 0 )		Disable	else		Enable	endifendifif ( OnActivate == 1 )PlaySound, "Torch Out"	if ( "cc_mar_lite3"->GetDisabled == 0 )		Disable	else		Enable	endifendifend

I've also tried if ( "cc_mar_lite3".state == 1 ) instead of if ( "cc_mar_lite3"->GetDisabled == 0 ) but it doesn't work too. What's more, sometimes the button is able to disappear completely when we activate it. I don't see any mistakes in my scipts so, really, I don't have any idea how to get around this problem.
User avatar
Dragonz Dancer
 
Posts: 3441
Joined: Sat Jun 24, 2006 11:01 am

Post » Thu May 03, 2012 3:44 am

I wrote these two scripts to light fires in fireplaces, or put them out, but the principle should be the same. I know these work:

Begin On_OffScript;On and off like a lightswitch;'*********************************************;' This script attaches to the button;'*********************************************short switchcont*;FireOn is global but should have a unique identifier like ModIDFireOnIf ( MenuMode == 1 )		ReturnendIfIf ( OnActivate == 1 )		set switchcont to 1endIfIf ( switchcont == 1 )	If ( FireOn == 0 )			set switchcont to 2	Else		set switchcont to 3	endIfendIfIf ( switchcont == 2 )		set FireOn to 1		set switchcont to 0endIfIf ( switchcont == 3 )		set FireOn to 0		set switchcont to 0endIf	End On_OffScript;'***************************************************;'This script attaches to the light ;'***************************************************Begin On_Off2Script;On and off like a lightswitchIf ( MenuMode == 1 )		ReturnendifIf ( FireOn == 0 )		Disable		ReturnendIfIf ( FireOn == 1 )		Enable		ReturnendIfEnd On_Off2Script
User avatar
jasminĪµ
 
Posts: 3511
Joined: Mon Jan 29, 2007 4:12 am

Post » Wed May 02, 2012 9:55 pm

I don't see any mistakes in my scipts
:) sorry, could not resist
lights should be unique and have reference persist on if you want to refer to them from script, no need to script them. I'd try something like this
begin cc_mar_s_litesbtn2if ( OnActivate )	PlaySound "Torch Out"	if ( cc_mar_lite2->GetDisabled )		cc_mar_lite2->enable		if ( cc_mar_lite1->GetDisabled )			cc_mar_lite1->enable		else			cc_mar_lite1->disable		endif		if ( cc_mar_lite3->GetDisabled )			cc_mar_lite3->enable		else			cc_mar_lite3->disable		endif	else		cc_mar_lite2->disable	endifendifendbegin cc_mar_s_litesbtn3if ( OnActivate )	PlaySound "Torch Out"	if ( cc_mar_lite3->GetDisabled )		cc_mar_lite3->enable		if ( cc_mar_lite2->GetDisabled )			cc_mar_lite2->enable		else			cc_mar_lite2->disable		endif		if ( cc_mar_lite4->GetDisabled )			cc_mar_lite4->enable		else			cc_mar_lite4->disable		endif	else		cc_mar_lite3->disable	endifendifendbegin cc_mar_s_litesbtn4if ( OnActivate )	PlaySound "Torch Out"	if ( cc_mar_lite4->GetDisabled )		cc_mar_lite4->enable		if ( cc_mar_lite3->GetDisabled )			cc_mar_lite3->enable		else			cc_mar_lite3->disable		endif		if ( cc_mar_lite5->GetDisabled )			cc_mar_lite5->enable		else			cc_mar_lite5->disable		endif	else		cc_mar_lite4->disable	endifendifend
I will leave the scripts for button 1 and 5 to you, as I don't know if you want to change state of light 1/5 when pressing button 5/1
User avatar
Jessica Stokes
 
Posts: 3315
Joined: Fri Jul 28, 2006 11:01 am

Post » Wed May 02, 2012 9:51 pm

and none of you quoted your IDs. :angry:

Lights also don't always disable properly, you're often better off moving them (say, z -1000 units).
User avatar
kristy dunn
 
Posts: 3410
Joined: Thu Mar 01, 2007 2:08 am

Post » Thu May 03, 2012 3:21 am

and none of you quoted your IDs. :angry:

Lights also don't always disable properly, you're often better off moving them (say, z -1000 units).

Wuhlll let me tell you, Pilgrim, I didn't quote my IDs cuz there aint no IDs in either script... Now go for your six shooter on the count of three... One,... one and a half... one and three-quarters... Wait, where wuz I? guess I'll have ta start over...
User avatar
GPMG
 
Posts: 3507
Joined: Sat Sep 15, 2007 10:55 am

Post » Thu May 03, 2012 3:44 am

Ok, first of all I made two, ridiculous mistakes. But before I write anything I would like to thank you for quick respond. Really, thanks!

So, in my script there was something like that:
if ( OnActivate == 1 )PlaySound, "Torch Out"        if ( "cc_mar_lite1"->GetDisabled == 0 )                Disable        else                Enable        endifendif
and there is no way to get any success by that, because Disable and Enabled refers to the button. I forgot to place ID before both functions and that's why my button was disappearing and I didn't know why.

The second mistake was in triple OnActivate functions. My overlook was enormous fault here. However, I used abot's script and it looks like that:

if ( OnActivate == 1 )PlaySound "Torch Out"if ( cc_mar_lite2->GetDisabled )cc_mar_lite2->enableelsecc_mar_lite2->disableendifendif

This example refers to cc_mar_lite2 but now it's very simple to include another lights (we have to copy internal IF-ENDIF part changing only ID of the light). Now everything works correctly, and riddle looks fantastic :)

Abot, I knew about reference persist and unique ID, but thanks for your hint anyway.
User avatar
Sakura Haruno
 
Posts: 3446
Joined: Sat Aug 26, 2006 7:23 pm

Post » Wed May 02, 2012 9:07 pm

and none of you quoted your IDs. :angry:
What can I say, never had a issue with not quoting proper identifiers (e.g. formed only by alphanumeric chars and underscore, not beginning with number or underscore), at least with a single operand ( id->function, no other parameters)
if function has parameters or there are more than 2 parts involved, I agree, it may be better to use them anyway (e.g player->GetItemCount "myProperID" or "player"->GetItemCount myProperID)
Lights also don't always disable properly, you're often better off moving them (say, z -1000 units).
Yes, you are right , I did not want to make script soon too complicated, I think a 1 pixel drift is enough to properly update collision/lightning after changing disabled/enabled state, e. g. (untested)
begin cc_mar_s_litesbtn3float z1	; main light Z pos temp storagefloat z2	; adiacent lights Z pos temp storageif ( OnActivate )	PlaySound "Torch Out"	set z1 to ( cc_mar_lite3->GetPos Z )	if ( cc_mar_lite3->GetDisabled )		set z1 to ( z1 + 1 )	; raise it a little to refresh ligtning/collision if mesh has it		cc_mar_lite3->enable		set z2 to ( cc_mar_lite2->GetPos Z )		if ( cc_mar_lite2->GetDisabled )			set z2 to ( z2 + 1 )			cc_mar_lite2->enable		else			set z2 to ( z2 - 1 )			cc_mar_lite2->disable		endif		"cc_mar_lite2"->SetPos Z z2	; here I think quoting identifier may be safer		set z2 to ( cc_mar_lite4->GetPos Z )		if ( cc_mar_lite4->GetDisabled )			set z2 to ( z2 + 1 )			cc_mar_lite4->enable		else			set z2 to ( z2 - 1 )			cc_mar_lite4->disable		endif		"cc_mar_lite4"->SetPos Z z2	else		set z1 to ( z1 - 1 )	; lower it a little		cc_mar_lite3->disable	endif	"cc_mar_lite3"->SetPos Z z1endifend
User avatar
Bee Baby
 
Posts: 3450
Joined: Sun Jun 18, 2006 4:47 am

Post » Wed May 02, 2012 3:07 pm

Now everything works correctly, and riddle looks fantastic :)
Nice :cool:
User avatar
aisha jamil
 
Posts: 3436
Joined: Sun Jul 02, 2006 11:54 am

Post » Thu May 03, 2012 2:52 am

What can I say, never had a issue with not quoting proper identifiers (e.g. formed only by alphanumeric chars and underscore, not beginning with number or underscore), at least with a single operand ( id->function, no other parameters)
if function has parameters or there are more than 2 parts involved, I agree, it may be better to use them anyway (e.g player->GetItemCount "myProperID" or "player"->GetItemCount myProperID)

You are correct, it's typically not. The compiler is easily confused, though.
I've actually been writing a flex/bison replacement compiler, and the original syntax is incredibly ambiguous, it's nearly impossible to properly parse without a lot of hard-coded hacks. The alternative is to require quoted IDs, which is safer now as general practice and in the future for replacement compilers.
User avatar
cassy
 
Posts: 3368
Joined: Mon Mar 05, 2007 12:57 am


Return to III - Morrowind