First attempt at scripting has my hair falling out!

Post » Sat May 28, 2011 10:32 am

Hokay so the basic gyst of it is im trying to make a switch that disables three poles(entryway for a giant cage in which giant creatures are kept) if they are enabled, enable them if disabled ect
my script will disable them but not re enable them! halp!

begin skeletonkingfreefloat Gateopenset Gateopen to 0if onactivate == 1If Gateopen == 0 skelpole1->Disable skelpole2->Disable skelpole3->Disable Set Gateopen to 1if Gateopen == 1Skelpole1->enableskelpole2->enableskelpole3->enableendifendifendifend

User avatar
suzan
 
Posts: 3329
Joined: Mon Jul 17, 2006 5:32 pm

Post » Fri May 27, 2011 11:17 pm

You may be better able to see the problem with the script if you indent it

begin skeletonkingfree    float Gateopen    set Gateopen to 0    if onactivate == 1        If Gateopen == 0             skelpole1->Disable             skelpole2->Disable             skelpole3->Disable             Set Gateopen to 1            if Gateopen == 1                Skelpole1->enable                skelpole2->enable                skelpole3->enable            endif        endif    endifend


When you activate it, it checks if gateopen is 0. If it is 0 it disables everything and sets gateopen to 1. It then checks if gateopen is 1 and enables everything

What you ment to do I think is:

begin skeletonkingfree    float Gateopen        set Gateopen to 0    if onactivate == 1        If Gateopen == 0             skelpole1->Disable             skelpole2->Disable             skelpole3->Disable             Set Gateopen to 1        endif        if Gateopen == 1            Skelpole1->enable            skelpole2->enable            skelpole3->enable            Set Gateopen to 0        endif    endifend


I it is also worth noting that if you shouldn't ever compare floats using equality. This is as floating point numbers can't represent all numbers exactly.

It is better to define gateopen as being a short. (Which can represent a subset of the natural numbers)

It may also may be better to enclose the condition for the if statement in brackets. Some people say it leads to bugs if you don't. I haven't ever seen a firm example of this though.

begin skeletonkingfree    short Gateopen        set Gateopen to 0    if ( onactivate == 1 )        If ( Gateopen == 0 )            skelpole1->Disable             skelpole2->Disable             skelpole3->Disable             Set Gateopen to 1        elseif ( Gateopen == 1 )            Skelpole1->enable            skelpole2->enable            skelpole3->enable            Set Gateopen to 0        endif    endifend


You could also use the getDisabled function rather than using a variable



begin skeletonkingfree    if ( onactivate == 1 )        If ( skelpole1->GetDisabled == 0 )            skelpole1->Disable             skelpole2->Disable             skelpole3->Disable        else            Skelpole1->enable            skelpole2->enable            skelpole3->enable        endif    endifend

User avatar
Mistress trades Melissa
 
Posts: 3464
Joined: Mon Jun 19, 2006 9:28 pm

Post » Sat May 28, 2011 6:21 am

Thanks man, i actually had your first suggestion implemented earlier but removed it during a period of trial and error, it did not work for whatever reason however the getdisabled method did, thank you!
ive been modding tes3 for a while but this is my first real script attempt beyond simply adding/removing items under certain conditions.
User avatar
Marine Arrègle
 
Posts: 3423
Joined: Sat Mar 24, 2007 5:19 am


Return to III - Morrowind