Jump to content

Need help with writing a door script.


Guest Messenjah

Recommended Posts

Guest Messenjah

Ok, so I'm trying to create a simple script. Mind you, this is my first script and I really need a better basic understanding of function and how

 

scripting works in general. I don't have a ton of time to work on this. I was hoping someone could help me correct this script and explain what you did

 

and I'll review it and try to correct it to the best of my abilities.

 

 

What it is supposed to do:

When the player activates and activator called "Mysterious Painting", the activator will check to see if PFVDoor is closed or not. Basically a toggle

 

switch for two doors.

 

If PFVDoor is closed, on activation,the script will open "PFVDoor" and will close "PFHatch".

If PFVDoor is open, on activation, the script will close "PFVDoor" and will open "PFHatch".

 

The reason for this script, is because it is possible in my level, for "PFVDoor" and "PFHatch" to both be closed at the same time, if this happens and I

 

have the two linked with an activate parent, both doors will toggle open upon activating the painting.

 

 

 

 

ScriptName MysteriousPaintingActivator

 

 

Begin OnActivate

If PFVDoor.GetOpenState == 1 ;if PFVDoor is open

PFVDoor.SetOpenState == 0 ;set PFVDoor to closed

PFHatch.SetOpenState == 1 ;set PFHatch to open

 

else ;however if PFVDoor is closed

PFVDoor.SetOpenState == 1 ;set PFVDoor to open

PFHatch.SetOpenState == 0 ;set PFHatch to closed

 

endif

End

Link to comment
Share on other sites

2 issues.

 

dont use == on setopen state command.

 

the Else flag might throw up some problems since there are more than 2 options for get open stat.

 

Gets the open state of an animating door. Return values:

 

0 = none (not a door)

1 = open

2 = opening

3 = closed

4 = closing

 

so if it is openeing or closing (mid animation) it will set to open.

 

i would opt to call a variable before the ifs, set it to the state, then run two if statements.

 

 

ScriptName MysteriousPaintingActivator

Begin OnActivate

 

Short openstate ;set a variable to store the open state of the pfvdoor

 

set openstate to PFVDoor.GetOpenState ;set the variable

 

 

If openstate == 1 ;if PFVDoor is open

PFVDoor.SetOpenState 0 ;set PFVDoor to closed

PFHatch.SetOpenState 1 ;set PFHatch to open

Endif

 

IF openstate == 3 ; if PFVDoor is closed

PFVDoor.SetOpenState 1 ;set PFVDoor to open

PFHatch.SetOpenState 0 ;set PFHatch to closed

endif

 

End

Link to comment
Share on other sites

Guest Messenjah

Hmmmm.... I couldn't find OpenState anywhere in the list of commands on the GECK wiki. I didn't know you could remove the Get, IS, etc on functions like that.

 

So you declare (tell) what variable is before you tell the variable what to do essentially?

Link to comment
Share on other sites

Hmmmm.... I couldn't find OpenState anywhere in the list of commands on the GECK wiki. I didn't know you could remove the Get, IS, etc on functions like that.

 

So you declare (tell) what variable is before you tell the variable what to do essentially?

 

openstate is just the variable name i used. you could changet that to anything you want, its just the temporary name i gave that stored number.

 

short (variable name) means that you going to be using some whole number in the future with the variable name as a call.

 

then just do if (variablename) == 1/0 to do all your calls on the IF/EndIf parts. that way you are only having to call out the reference once. (when you set (variablename) to XXX

 

the "set (variable) to XXX" basically replaces the Get/Is stuff

Link to comment
Share on other sites

Guest Messenjah

Oh, ok.

 

 

set openstate to PFVDoor.GetOpenState ;set the variable

 

 

Basically, you are re-naming PFVDoor.GetOpenState to openstate then? So openstate is actually, PFVDoor.GetOpenState?

 

Then you just use two IF's instead of else.

 

I kinda wondered if the script I wrote would call on itself to re-open the door when I wrote it. So, that is why you made two IF statements.

 

 

 

Also:

 

Short openstate

 

This basically means, the variable called openstate uses whole numbers, correct?

Link to comment
Share on other sites

Guest Messenjah

Ok, so I experimented with your script.

 

I re-wrote it to this:

 

ScriptName MysteriousPaintingActivator

Begin OnActivate

 

 

 

 

If PFVDoor.GetOpenState == 1 ;if PFVDoor is open

PFVDoor.SetOpenState 0 ;set PFVDoor to closed

PFHatch.SetOpenState 1 ;set PFHatch to open

Endif

 

If PFVDoor.GetOpenState == 3 ; if PFVDoor is closed

PFVDoor.SetOpenState 1 ;set PFVDoor to open

PFHatch.SetOpenState 0 ;set PFHatch to closed

endif

 

End

 

 

So, I'm assuming that what I am asking you is correct and that you are just renaming PFVDoor.GetOpenState to openstate

 

 

The other thing I'm wondering, is why did you re-name it? Also, why is it so important to add the "Short" to a script? I've noticed a lot of activator scripts do not contain "Short". Does it just make the script run smoother and less buggy by telling it to make sure to use whole numbers?

 

I would assume that this would only be necessary if there were other variables to add non-whole numbers or if the script was REALLY big?

Link to comment
Share on other sites

ok, just to backtrack a step.

 

your code will work as you have it, but might have issues if you use it for other things.

 

Short - this command tells the script editor that you are about to create a new "Short" variable (think of it as a container to store a number). short variables are whole numbers, 1 2 3 etc. Float is another command you can use to store numbers. Float is used for decimal points, so 1.23 or 4.575 etc.

 

so the way your code is written there could potentially be an issue (though due to the speed of the script and the fact that opening and closing are extra states you will be ok).

 

Here is how that could end up a problem if the door starts open.

 

 

If PFVDoor.GetOpenState == 1 ;if PFVDoor is open (check to see if the door is open, it is)

PFVDoor.SetOpenState 0 ;set PFVDoor to closed (close the door)

PFHatch.SetOpenState 1 ;set PFHatch to open

Endif

 

If PFVDoor.GetOpenState == 3 ; if PFVDoor is closed (check to see if the door is closed. it is, because you just closed it)

PFVDoor.SetOpenState 1 ;set PFVDoor to open (open the door)

PFHatch.SetOpenState 0 ;set PFHatch to closed

endif

 

 

so if it was an instant animation, it would open, then close quickly all within one run of the script. to avoid this, create a variable (command is short (variable name) )

 

then run the getopenstate command and store the result in the variable. so the line

 

Set (variable name) PFVDoor.getopenstate

 

now set the variable called (variable name) to be = to the value of GetOpenState. in the example above that is 1.

 

now instead of calling for getopenstate every time, you just use the stored number by saying (variable name).

Link to comment
Share on other sites

Guest Messenjah

So basically, what you are saying is that without using Short, it could see it as any variable so it could be a decimal number or a whole but since nothing is set, the script speed will be instant. However, opening and closing doors that are animated, already have their speed set up in the animation itself and are also hardcoded?

 

 

I was thinking you could use:

 

Short PFVDoor.GetOpenState

 

Instead of:

 

Short openstate

 

Set openstate to PFVDoor.GetOpenState

 

 

I'm assuming that the reason that you don't do this, is because 1, you are declaring an object reference and GetOpenState is a condition, not a variable and 2, it is easier than writing PFVDoor.GetOpenState?

Link to comment
Share on other sites

So basically, what you are saying is that without using Short, it could see it as any variable so it could be a decimal number or a whole but since nothing is set, the script speed will be instant. However, opening and closing doors that are animated, already have their speed set up in the animation itself and are also hardcoded?

 

 

I was thinking you could use:

 

Short PFVDoor.GetOpenState

 

Instead of:

 

Short openstate

 

Set openstate to PFVDoor.GetOpenState

 

 

I'm assuming that the reason that you don't do this, is because 1, you are declaring an object reference and GetOpenState is a condition, not a variable and 2, it is easier than writing PFVDoor.GetOpenState?

 

you got it : )

Link to comment
Share on other sites

Guest Messenjah

Cool! I'm very thankful for your help! It's really, easier to learn scripting when you are hands-on and sometimes the GECK wiki doesn't always cover what you are looking at doing. I really appreciate your help! This explains it a lot better than even the Wiki explains it.

 

I'm going to see if I can figure out how to add time delays in the script now. :o)

 

I've actually written a number of door scripts since you explained this to me! :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...