?'s about statements i'm seeing in a couple mods

Post » Fri Dec 05, 2014 3:49 pm

I'm seeing things like . . .

Cell kCell = Game.GetPlayer().GetParentCell()ObjectReference objRef

It's clear in these cases what Cell and ObjectReference are, and that kCell and objRef are variables . . . that the entire thing is about setting variables in the right context . . .

My question is this: When the search function decides to actually work on the CKWiki (anyone else get a blank page for search resulte?), I don't see reference to being able to use that function like that.

Is there documentation on how and when you're able to do this?

User avatar
Kari Depp
 
Posts: 3427
Joined: Wed Aug 23, 2006 3:19 pm

Post » Fri Dec 05, 2014 10:14 pm

Calling functions only makes sense when inside some event or other function.Game.GetPlayer().GetParentCell() will simply return the cell the player is in at the time that function is called, so context matters.
User avatar
Laura Wilson
 
Posts: 3445
Joined: Thu Oct 05, 2006 3:57 pm

Post » Sat Dec 06, 2014 4:10 am

Ok thanks.

is there docs on these 2 functions somwhere?

are there other functions like this? where would I read up on it/them?

User avatar
Dean Ashcroft
 
Posts: 3566
Joined: Wed Jul 25, 2007 1:20 am

Post » Sat Dec 06, 2014 1:32 am

http://www.creationkit.com/Category:Papyrus
All the functions are documented there, except for some skse ones.
User avatar
Alyesha Neufeld
 
Posts: 3421
Joined: Fri Jan 19, 2007 10:45 am

Post » Fri Dec 05, 2014 4:53 pm

Yeah, noticed that yesterday as well, and still seems to be doing it. Not a good season for searching, I guess :D

User avatar
Scared humanity
 
Posts: 3470
Joined: Tue Oct 16, 2007 3:41 am

Post » Sat Dec 06, 2014 2:29 am



The functions Cell and ObjectReference are not documented on those pages in the context I gave. Those pages give the example of using those functions in the header of a script, and not the "in-line" use.

Why would I use them in-line? Is there documentation explaining in-line use?

[edit] to be more specific

Why do I need the statement

Cell kCell = Game.GetPlayer().GetParentCell()

why couldn't I just go

kCell = Game.GetPlayer().GetParentCell()

1) Why does Cell need to be there?

2) Is there docs on using Cell (and others) in that context?

User avatar
He got the
 
Posts: 3399
Joined: Sat Nov 17, 2007 12:19 pm

Post » Fri Dec 05, 2014 10:06 pm

You need to declare a Cell variable in order to assign a value to it. Including the word "Cell" before "kCell" declares kCell as a new variable of the Cell type. Thus, you could also do:

Cell kCellkCell = Game.GetPlayer().GetParentCell()

Depending what you are doing with that value you may not even need to store the value in kCell at all, you could just compare it to something else. Example:

if someObject.GetParentCell() == Game.GetPlayer().GetParentCell()    ;if the object and the player are in the same cell, do somethingendif
User avatar
Farrah Barry
 
Posts: 3523
Joined: Mon Dec 04, 2006 4:00 pm

Post » Fri Dec 05, 2014 12:31 pm

Alright, gotcha.

Now here is the part that gets me...

What are the rules for when that declaration is necessary? Are they stated in docs somewhere?

User avatar
Imy Davies
 
Posts: 3479
Joined: Fri Jul 14, 2006 6:42 pm

Post » Fri Dec 05, 2014 9:38 pm

All variables that you use must be declared somewhere in your script. Variables can only be declared one time. So, for example, this would result in an error:

Cell kCellkCell = NoneCell kCell = Game.GetPlayer().GetParentCell() ;this line causes an error, since you can't re-declare the same variable a second time.

You'll need to declare a variable whenever you want to store or "hold" a value to be used later (because there is no other way to store/hold values besides variables)

The only time you wouldn't need to declare a variable is if it's passed into your function (or event) as a parameter. In that case, the variable is automatically declared by the function when the function is called. So, for instance, this is perfectly valid:

Event OnActivate(ObjectReference akActionRef)    akActionRef = None  ;We don't need to say "ObjectReference akActionRef", because akActionRef already is declared when it is passed as a parameter into this event.EndEvent

You might want to give http://www.creationkit.com/Variables_and_Properties a read for more info.

User avatar
Marquis deVille
 
Posts: 3409
Joined: Thu Jul 26, 2007 8:24 am

Post » Sat Dec 06, 2014 4:09 am

That's not what I'm talkin about. Yes variables need to be declared.

What I'm talking about is when you said:

So based on that. . .

Depending on what? Is there docs on those rules?

User avatar
Astargoth Rockin' Design
 
Posts: 3450
Joined: Mon Apr 02, 2007 2:51 pm

Post » Fri Dec 05, 2014 4:06 pm

Variables are simply easy (and fast) storage for values. So you use them whenever you might need to use a value multiple times (because calling a function to get the value multiple times is slower than simply accessing a value in a variable) or because it makes your code easier to read and understand.From the example above, if you just want to see if the player is in the same cell as one particular object, you wouldn't use a variable like monsto's example.On the other hand if I wanted to see if the player was in the same cell as more than one object then I would use a variable something like this:
Actor Property PlayerREF Auto  ; using a property for this is faster than calling Game.GetPlayer()Actor Property ViljaRef Auto   ; These would have to be filled with the appropriate actor references placed in the game world.Actor Property InigoRef AutoActor Property LydiaRef AutoActor Property MarcurioRef AutoEvent OnUpdate()     Cell PlayerCell = PlayerRef.GetParentCell()  ; store this since it's being used multiple times     if PlayerCell == ViljaRef.GetParentCell()          Debug.Notification("Vilja is nearby.")     endif     if PlayerCell == InigoRef.GetParentCell()          Debug.Notification("Inigo is nearby.")     endif     if PlayerCell == LydiaRef.GetParentCell()          Debug.Notification("Lydia is nearby.")     endif     if PlayerCell == MarcurioRef.GetParentCell()          Debug.Notification("Marcurio is nearby.")     endifEndEvent
You should work through some of the scripting tutorials to get a better understanding of how all of the parts go together.
User avatar
Johnny
 
Posts: 3390
Joined: Fri Jul 06, 2007 11:32 am


Return to V - Skyrim