Global functions

Post » Mon Jun 18, 2012 4:09 pm

So how exactly does one make them work?

I can't seem to figure it out myself.

I read the wiki article about functions, and I tried recreating what it did, but when I compile it says that my function doesn't exist.

Here's my function script:

Scriptname MyFunctionTestScript HiddenFunction MyTestFunction(int buttonPressed) Globalif buttonPressed == 0    Debug.MessageBox("Button 1 pressed.")Elseif buttonPressed == 1    Debug.MessageBox("Button 2 pressed.")Elseif buttonPressed == 2    Debug.MessageBox("Button 3 pressed.")Else    Debug.MessageBox("Button 4 pressed.")EndIfEndFunction

And supposedly I should just be able to put MyTestFunction(#) in a different script, right?
User avatar
Lily Something
 
Posts: 3327
Joined: Thu Jun 15, 2006 12:21 pm

Post » Mon Jun 18, 2012 9:49 pm

I have no idea that "global" functions existed. I have to create a script extending quest, add it to a quest set to start on game start and bung the function in there.

Then in another script you need to add a property linking to the quest. to call the remote function you have to do:

myScriptName varName = myQuest as myScriptName
varName.doSomething()

Where "myScriptName" is the name of the script on the remote quest and "myQuest" is the name of the quest property. varName can be anything you want.
User avatar
Rob
 
Posts: 3448
Joined: Fri Jul 13, 2007 12:26 am

Post » Mon Jun 18, 2012 9:26 am

What you want to use in your other script is the following:

MyFunctionTestScript.MyTestFunction(myVariable)

You have to prefix the global function with the script it is contained in so the compiler knows where to look. If you don’t want to type the name of the script and you end up using a lot of global functions from the same script, you can also “import” the script by putting “import MyFunctionTestScript” near the top of your script. (http://www.creationkit.com/Import#Imports)
User avatar
Reanan-Marie Olsen
 
Posts: 3386
Joined: Thu Mar 01, 2007 6:12 am

Post » Mon Jun 18, 2012 8:44 pm

What you want to use in your other script is the following:

MyFunctionTestScript.MyTestFunction(myVariable)

You have to prefix the global function with the script it is contained in so the compiler knows where to look. If you don’t want to type the name of the script and you end up using a lot of global functions from the same script, you can also “import” the script by putting “import MyFunctionTestScript” near the top of your script. (http://www.creationkit.com/Import#Imports)
Wow, thank you.

The function wiki page talking about global functions is a way too vague.
User avatar
Charlotte Buckley
 
Posts: 3532
Joined: Fri Oct 27, 2006 11:29 am

Post » Mon Jun 18, 2012 11:58 am

Cool never knew that, thanks!
User avatar
Nichola Haynes
 
Posts: 3457
Joined: Tue Aug 01, 2006 4:54 pm

Post » Mon Jun 18, 2012 2:55 pm

Hmm.

Is there any way to get a function to display a message?
User avatar
jasminε
 
Posts: 3511
Joined: Mon Jan 29, 2007 4:12 am

Post » Mon Jun 18, 2012 11:35 pm

For a quick message do a

debug.messagebox("hello")

or link a MESSAGE property to the script and point it at an actualy message you have created.

Then do a:

myMessageProperty.Show()
User avatar
Meghan Terry
 
Posts: 3414
Joined: Sun Aug 12, 2007 11:53 am

Post » Mon Jun 18, 2012 4:38 pm

How do you set a property on a script that's not attached to anything? There's no "Properties" button in the script manager window.
User avatar
Javaun Thompson
 
Posts: 3397
Joined: Fri Sep 21, 2007 10:28 am

Post » Mon Jun 18, 2012 5:13 pm

A script that's not attached to anything can never run, although you can use it as a library for global functions. You must attach it to something before you can set properties through the editor. You should still be able to do this, I think, but you can't use object properties as your script won't be associated with any data files:
int property IntProp = 1 auto

Cipscis

EDIT:

For messages, I find http://www.creationkit.com/Notification_-_Debug to be very useful.

Cipscis
User avatar
Joey Bel
 
Posts: 3487
Joined: Sun Jan 07, 2007 9:44 am

Post » Mon Jun 18, 2012 9:06 pm

I'm also interested to know how to attach something to a "standalone" script, it's possible or not ?
User avatar
Jack Moves
 
Posts: 3367
Joined: Wed Jun 27, 2007 7:51 am

Post » Mon Jun 18, 2012 9:33 pm

So is there anyway to do the following?

Scriptname showMessageFunctionScript extends ObjectReferenceMessage Property myMessage AutoFunction showMessageFunction() Global	int buttonPressed = myMessage.Show()EndFunction

Works just fine if "Global" isn't there.
User avatar
Esther Fernandez
 
Posts: 3415
Joined: Wed Sep 27, 2006 11:52 am

Post » Mon Jun 18, 2012 5:10 pm

Not quite sure what you are trying to achieve but best bet is to create a quest (set to run on game start) that has your "global" script attached to it and you functions you want to call from other scripts. Then you can attach the properties you need to it and you can then call its functions from other scripts.
User avatar
Amber Ably
 
Posts: 3372
Joined: Wed Aug 29, 2007 4:39 pm

Post » Mon Jun 18, 2012 9:07 am

Seems like a very convoluted way to achieve what should be a simple task.

Surely there's something I'm missing/doing wrong that's preventing this from working.
User avatar
Tyrel
 
Posts: 3304
Joined: Tue Oct 30, 2007 4:52 am

Post » Mon Jun 18, 2012 2:25 pm

Ha, got it.



Function displayStyleMessage(Message styleMessage) Globalint buttonPressed = styleMessage.Show()

Duh. Not sure why I didn't do that in the first place.
User avatar
Sheeva
 
Posts: 3353
Joined: Sat Nov 11, 2006 2:46 am

Post » Mon Jun 18, 2012 5:05 pm

Now does anyone know how to get the reference of an object placed using a function?

placedItem = spawnPoint.PlaceAtMe(itemToPlace)
Complains about placedItem not existing.
User avatar
anna ley
 
Posts: 3382
Joined: Fri Jul 07, 2006 2:04 am

Post » Tue Jun 19, 2012 12:54 am

That sounds like you haven't declared a property or variable called "placedItem". Try adding this line to the top of your script:
ObjectReference placedItem

Cipscis
User avatar
josie treuberg
 
Posts: 3572
Joined: Wed Feb 07, 2007 7:56 am

Post » Tue Jun 19, 2012 12:22 am

That's what I figured, since that's what I always did before.

Scriptname GlobalFunctionTestScript extends ObjectReference  ObjectReference placedItemFunction testFunction(Message testMessage, ObjectReference spawnPoint, Static itemToPlace) Globalint buttonPressed = TestMessage.Show()if buttonPressed == 0    placedItem = spawnPoint.PlaceAtMe(itemToPlace)ElseIf buttonPressed == 1    placedItem = spawnPoint.PlaceAtMe(itemToPlace)ElseEndIfEndFunction

Does that look right?

Because when I try and compile, it says:

d:\program files\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\GlobalFunctionTestScript.psc(10,1): variable placedItem is undefined
d:\program files\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\GlobalFunctionTestScript.psc(10,1): type mismatch while assigning to a none (cast missing or types unrelated)
d:\program files\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\GlobalFunctionTestScript.psc(12,1): variable placedItem is undefined

Which would work if it wasn't a "Global" function. Is there a different method for global functions?

And I can't put it in the function's variables without a default value, but if I did that it would just set it back to the default value every time the function ran, wouldn't it? Thus not being able to actually do anything with it.
User avatar
Chrissie Pillinger
 
Posts: 3464
Joined: Fri Jun 16, 2006 3:26 am

Post » Mon Jun 18, 2012 9:46 pm

http://www.creationkit.com/Notification_-_Debug

Nice link. i hadn't seen that one. Thank you.
User avatar
Cassie Boyle
 
Posts: 3468
Joined: Sun Nov 05, 2006 9:33 am

Post » Mon Jun 18, 2012 12:18 pm

Cannot for the life of me figure this out.

This works:
Spoiler
Scriptname MessageScript extends Object ReferenceStatic Property staticToPlace AutoObjectReference Property spawnLocation AutoObjectReference Property placedStatic AutoObjectReference Property placedStatic2 AutoMessage Property MessageToShow AutoEvent OnActivate(ObjectReference akActivator)int buttonPressed = MessageToShow.Show()If buttonPressed == 0   placedStatic = spawnLocation.PlaceAtMe(staticToPlace)Else   placedStatic = spawnLocation.PlaceAtMe(staticToPlace2)EndIfEndEvent

And this works:

Spoiler
Scriptname MessageScript extends Object ReferenceStatic Property staticToPlace AutoObjectReference Property spawnLocation AutoObjectReference Property placedStatic AutoObjectReference Property placedStatic2 AutoMessage Property MessageToShow AutoEvent OnActivate(ObjectReference akActivator)	MessageFunction()EndEvent;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Function MessageFunction()int buttonPressed = MessageToShow.Show()If buttonPressed == 0   placedStatic = spawnLocation.PlaceAtMe(staticToPlace)Else   placedStatic = spawnLocation.PlaceAtMe(staticToPlace2)EndIfEndFunction


But is there any way at all to split them into two scripts, and have the function be a Global? All of my attempts either complain about variables not existing or a lack of a default value.

I can almost get it to do what I want, It will spawn the items, but it won't let me reference them, I can't seem to just do
placedStatic  = pawnLocation.PlaceAtMe(staticToPlace)
the way I want.
User avatar
Britta Gronkowski
 
Posts: 3475
Joined: Mon Apr 09, 2007 3:14 pm

Post » Tue Jun 19, 2012 12:07 am

I supposed I should clarify a little more.
Here's basically what I'm trying to get it to do:

placedStatic.Delete()placedStatic  = pawnLocation.PlaceAtMe(staticToPlace)

I want it to when I push a button, it deletes the currently placed static, and adds a new one.


I can get it to spawn a static, but it won't delete the old one, as I can't reference it properly.

The closest I got was changing it to this:

placedStatic.Delete()ObjectReference placedStatic  = pawnLocation.PlaceAtMe(staticToPlace)
But when I tried using it in the If statments, it doesn't seem to work between them.
User avatar
Danii Brown
 
Posts: 3337
Joined: Tue Aug 22, 2006 7:13 am


Return to V - Skyrim