Creating A Function Within A Fragment

Post » Thu Jun 21, 2012 12:49 pm

I'm playing around with a small function that should set two characters into a fist fight within a Scene.

For the actual script I have this:

;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment;NEXT FRAGMENT INDEX 1Scriptname TIF__0202C1B1 Extends TopicInfo HiddenFunction FightStart(Actor NPC1, Actor NPC2)   NPC1.SetLookAt(NPC2, true)   NPC2.SetLookAt(NPC1, true)   NPC1.GetActorBase().SetInvulnerable(true)   NPC2.GetActorBase().SetInvulnerable(true)   NPC1.StartCombat(NPC2)   NPC2.StartCombat(NPC1)EndFunction;END FRAGMENT CODE - Do not edit anything between this and the begin commentReferenceAlias Property Alias_Glathor  Auto  ReferenceAlias Property Alias_Engar  Auto

And the call to the FightStart function, which is placed in the End fragment of the dialog in the scene is:

FightStart(Alias_Glathor.GetActorReference(), Alias_Engar.GetActorReference())

The error I am getting is:

FightStart is not a function or does not exist

What am I doing wrong?

Thanks for any and all help :)
User avatar
Anthony Rand
 
Posts: 3439
Joined: Wed May 09, 2007 5:02 am

Post » Thu Jun 21, 2012 10:34 am

I don't think a function inside a fragment will work.
It's easier (and better I think) to add a property to the fragment and then call your function located in another script.

MyScript Property Call Auto

In your fragment:

Call.FightStart(Alias_Glathor.GetActorReference(), Alias_Engar.GetActorReference())
User avatar
x a million...
 
Posts: 3464
Joined: Tue Jun 13, 2006 2:59 pm

Post » Thu Jun 21, 2012 12:25 pm

I don't think a function inside a fragment will work.
It's easier (and better I think) to add a property to the fragment and then call your function located in another script.

MyScript Property Call Auto

In your fragment:

Call.FightStart(Alias_Glathor.GetActorReference(), Alias_Engar.GetActorReference())

What is MyScript?

I get an error for it

Thanks!
User avatar
Richus Dude
 
Posts: 3381
Joined: Fri Jun 16, 2006 1:17 am

Post » Thu Jun 21, 2012 6:07 pm

Was I supposed to put "MyScript Property Call Auto" into the script of the fragment?
User avatar
Daniel Holgate
 
Posts: 3538
Joined: Tue May 29, 2007 1:02 am

Post » Thu Jun 21, 2012 4:36 pm

"Myscript" is a placeholder for the actual scriptname of the script where you have written the function to be called.

Yes, open the frament in the script editor and add it below the "Do Not Edit" comments.

Because you're adding a script property, you will not be able to add it using the Properties button.

But you DO fill it with the button, it won't auto fill but it should show the quest it extends in the drop down box.
User avatar
Antony Holdsworth
 
Posts: 3387
Joined: Tue May 29, 2007 4:50 am

Post » Thu Jun 21, 2012 10:25 am

"Myscript" is a placeholder for the actual scriptname of the script where you have written the function to be called.

Yes, open the frament in the script editor and add it below the "Do Not Edit" comments.

Because you're adding a script property, you will not be able to add it using the Properties button.

But you DO fill it with the button, it won't auto fill but it should show the quest it extends in the drop down box.

The name of the script that Ingenue created for the mod is called "LBGQ30fistfight", which pretty much only holds the function....FightStart(Actor NPC1, Actor NPC2)

So, in the fragment source I would add something like "LBGQ30fistfight Property Call Auto"?
User avatar
Beth Belcher
 
Posts: 3393
Joined: Tue Jun 13, 2006 1:39 pm

Post » Thu Jun 21, 2012 2:29 pm

Meh

Adding "LBGQ30fistfight Property Call Auto" to the fragment source didn't make them fight :confused:
User avatar
Taylor Tifany
 
Posts: 3555
Joined: Sun Jun 25, 2006 7:22 am

Post » Thu Jun 21, 2012 7:34 pm

I would add a debug.messagebox in the function to verify it is being called.
It may be that you also need to add the alias properties to the fragment as well. idk.
I do know this method does work in a quest fragment - I assume it would work in an object fragment.
I use it extensively in one of my mods.
User avatar
Rhiannon Jones
 
Posts: 3423
Joined: Thu Sep 21, 2006 3:18 pm

Post » Fri Jun 22, 2012 1:44 am

The function isn't being called....drats!

Here's the script contents:

Scriptname LBGQ30fistfight extends ObjectReferenceFunction FightStart(Actor NPC1, Actor NPC2)debug.messagebox("Fight Works!")   NPC1.SetLookAt(NPC2, true)   NPC2.SetLookAt(NPC1, true)   NPC1.GetActorBase().SetInvulnerable(true)   NPC2.GetActorBase().SetInvulnerable(true)   NPC1.StartCombat(NPC2)   NPC2.StartCombat(NPC1)EndFunctionAlias Property Alias_Engar  Auto  Alias Property Alias_Glathor  Auto

And the fragment is "Call.FightStart(Alias_Glathor.GetActorReference(), Alias_Engar.GetActorReference())"

In the fragment source I added the line "LBGQ30fistfight Property Call Auto"
User avatar
Mark Hepworth
 
Posts: 3490
Joined: Wed Jul 11, 2007 1:51 pm

Post » Thu Jun 21, 2012 4:56 pm

Do you have script logging enabled? Maybe that could help show what's going on.

I wonder if you also need to add the alias properties to the fragment as well...

How is this fragment triggered?
User avatar
Suzie Dalziel
 
Posts: 3443
Joined: Thu Jun 15, 2006 8:19 pm

Post » Thu Jun 21, 2012 6:21 pm

If you want to make your life easier:
  • Place your normal script containing your function into the regular Scripts area for your quest and fill in all the properties that need filling.
  • Go to the Stage fragment you want to call your function in, place a semicolon in the box.
  • Open the dropdown box for kMyQuest, and select the script containing your function.
  • Compile the fragment and exit.
  • Return to your fragment, and type in "kMyQuest.()", and recompile.
This will have the CK make a property reference to the script containing the function you want to use for you.
User avatar
Sophie Morrell
 
Posts: 3364
Joined: Sat Aug 12, 2006 11:13 am

Post » Thu Jun 21, 2012 6:50 pm

If you want to make your life easier:
  • Place your normal script containing your function into the regular Scripts area for your quest and fill in all the properties that need filling.
  • Go to the Stage fragment you want to call your function in, place a semicolon in the box.
  • Open the dropdown box for kMyQuest, and select the script containing your function.
  • Compile the fragment and exit.
  • Return to your fragment, and type in "kMyQuest.()", and recompile.
This will have the CK make a property reference to the script containing the function you want to use for you.

Looking at the current function he's trying to access, it is not attached to a quest.
User avatar
Dominic Vaughan
 
Posts: 3531
Joined: Mon May 14, 2007 1:47 pm

Post » Thu Jun 21, 2012 11:54 pm

Looking at the current function he's trying to access, it is not attached to a quest.

You can't do that. I tried with linking an ActiveMagicEffect script to a Quest script for variable transfer before now, and it just didn't work. Check the Properties window, if you find you are unable to give that property a specific value, what you are attempting is impossible. You have to contain your function in a Quest script if you want to use it in your quest's fragments or call it from another quest.
User avatar
Fam Mughal
 
Posts: 3468
Joined: Sat May 26, 2007 3:18 am

Post » Thu Jun 21, 2012 6:09 pm

I haven't tried your suggestions yet but would the problem not be because I am calling the fight to start during the scene when other NPCs are saying their dialog?
User avatar
Logan Greenwood
 
Posts: 3416
Joined: Mon Jul 30, 2007 5:41 pm

Post » Thu Jun 21, 2012 12:26 pm

If you want to make your life easier:
  • Place your normal script containing your function into the regular Scripts area for your quest and fill in all the properties that need filling.
  • Go to the Stage fragment you want to call your function in, place a semicolon in the box.
  • Open the dropdown box for kMyQuest, and select the script containing your function.
  • Compile the fragment and exit.
  • Return to your fragment, and type in "kMyQuest.()", and recompile.
This will have the CK make a property reference to the script containing the function you want to use for you.

But I wouldn't be able to call the function within the scene, right?

Here is a screenshot of the part of the scene where I want the fight to start. It shows the dialog "What did you just say?" and the fragment where I've been trying to get the fight to start:

http://lamplight.pcgamingnetwork.com/viewtopic.php?f=2&t=29
User avatar
HARDHEAD
 
Posts: 3499
Joined: Sun Aug 19, 2007 5:49 am

Post » Thu Jun 21, 2012 12:36 pm

If you want to make your life easier:
  • Place your normal script containing your function into the regular Scripts area for your quest and fill in all the properties that need filling.
  • Go to the Stage fragment you want to call your function in, place a semicolon in the box.
  • Open the dropdown box for kMyQuest, and select the script containing your function.
  • Compile the fragment and exit.

I get the error "... cannot cast a quest to a lbgq30fistfight, types are incompatible" when I try this
User avatar
Dan Wright
 
Posts: 3308
Joined: Mon Jul 16, 2007 8:40 am

Post » Thu Jun 21, 2012 1:48 pm

As I said above, what you are trying to do will not work. Only Quest scripts can be used in the manner both myself and aellis described. Yours is not, so you will need to find another method.

I'd suggest removing the Function altogether and just calling everything up in the TopicInfo script loose. No need to be overly complex:

;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment;NEXT FRAGMENT INDEX 1Scriptname TIF__0202C1B1 Extends TopicInfo Hidden   Alias_Glathor.GetActorReference().SetLookAt(Alias_Engar.GetActorReference(), true)   Alias_Engar.GetActorReference().SetLookAt(Alias_Glathor.GetActorReference(), true)   Alias_Glathor.GetActorBase().SetInvulnerable(true)   Alias_Engar.GetActorBase().SetInvulnerable(true)   Alias_Glathor.GetActorReference().StartCombat(Alias_Engar.GetActorReference())   Alias_Engar.GetActorReference().StartCombat(Alias_Glathor.GetActorReference());END FRAGMENT CODE - Do not edit anything between this and the begin commentReferenceAlias Property Alias_Glathor  Auto  ReferenceAlias Property Alias_Engar  Auto
User avatar
Maya Maya
 
Posts: 3511
Joined: Wed Jul 05, 2006 7:35 pm

Post » Thu Jun 21, 2012 6:05 pm

"calling everything up in the TopicInfo script loose"

Sorry, I don't understand :)
User avatar
Cassie Boyle
 
Posts: 3468
Joined: Sun Nov 05, 2006 9:33 am

Post » Thu Jun 21, 2012 1:40 pm

See the code snippet I added in. I mean just get rid of the Function()/EndFunction lines and put everything inside of it into your specific Topic result fragment that triggers the fight.
User avatar
Assumptah George
 
Posts: 3373
Joined: Wed Sep 13, 2006 9:43 am

Post » Thu Jun 21, 2012 2:00 pm

I have this where it will compile:

;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment;NEXT FRAGMENT INDEX 2Scriptname TIF__0202C1B1 Extends TopicInfo Hidden   Alias_Glathor.GetActorReference().SetLookAt(Alias_Engar.GetActorReference(), true)   Alias_Engar.GetActorReference().SetLookAt(Alias_Glathor.GetActorReference(), true)   Alias_Glathor.GetActorBase().SetInvulnerable(true)   Alias_Engar.GetActorBase().SetInvulnerable(true)   Alias_Glathor.GetActorReference().StartCombat(Alias_Engar.GetActorReference())   Alias_Engar.GetActorReference().StartCombat(Alias_Glathor.GetActorReference())T;END FRAGMENT CODE - Do not edit anything between this and the begin commentReferenceAlias Property Alias_Glathor  Auto  ReferenceAlias Property Alias_Engar  Auto

But how would I call that to start the fight?

What would the syntax be for the end fragment?
User avatar
JD FROM HELL
 
Posts: 3473
Joined: Thu Aug 24, 2006 1:54 am

Post » Thu Jun 21, 2012 5:04 pm

Put this:

Alias_Glathor.GetActorReference().SetLookAt(Alias_Engar.GetActorReference(), true)Alias_Engar.GetActorReference().SetLookAt(Alias_Glathor.GetActorReference(), true)Alias_Glathor.GetActorBase().SetInvulnerable(true)Alias_Engar.GetActorBase().SetInvulnerable(true)Alias_Glathor.GetActorReference().StartCombat(Alias_Engar.GetActorReference())Alias_Engar.GetActorReference().StartCombat(Alias_Glathor.GetActorReference())

Into the End Fragment for your Topic.
User avatar
OnlyDumazzapplyhere
 
Posts: 3445
Joined: Wed Jan 24, 2007 12:43 am

Post » Thu Jun 21, 2012 10:53 am

That will get the job done.

However I think it is better simply to give your quest a script, and put as much as possible of your code into that quest script, just to help keep it all in the same place, not scattered around in different fragments. That way you can keep track of, reuse, change, and add to your code much more easily.

If you give your quest a script called MyQuestScript, for example, you can call any functions in it from a scene in that quest like this:

MyQuestScript QS = (GetOwningQuest() as MyQuestScript)
QS.SomeQuestFunction()
User avatar
Alan Cutler
 
Posts: 3163
Joined: Sun Jul 01, 2007 9:59 am

Post » Thu Jun 21, 2012 9:43 pm

Put this:
Alias_Glathor.GetActorReference().SetLookAt(Alias_Engar.GetActorReference(), true) Alias_Engar.GetActorReference().SetLookAt(Alias_Glathor.GetActorReference(), true) Alias_Glathor.GetActorBase().SetInvulnerable(true) Alias_Engar.GetActorBase().SetInvulnerable(true) Alias_Glathor.GetActorReference().StartCombat(Alias_Engar.GetActorReference()) Alias_Engar.GetActorReference().StartCombat(Alias_Glathor.GetActorReference())
Into the End Fragment for your Topic.

I tried that but "GetActorBase()" wasn't recognized as a function.

However, the NPCs did fight without that.

The problem is that the scene hangs with them fighting and dialog stops.
User avatar
Silvia Gil
 
Posts: 3433
Joined: Mon Nov 20, 2006 9:31 pm

Post » Thu Jun 21, 2012 5:54 pm

That will get the job done. However I think it is better simply to give your quest a script, and put as much as possible of your code into that quest script, just to help keep it all in the same place, not scattered around in different fragments. That way you can keep track of, reuse, change, and add to your code much more easily. If you give your quest a script called MyQuestScript, for example, you can call any functions in it from a scene in that quest like this: MyQuestScript QS = (GetOwningQuest() as MyQuestScript) QS.SomeQuestFunction()

I'm thinking the best way to tackle this is with a new quest, a fist fight quest.

Would that not allow the fight to go on while the other NPCs do their dialog, then when the time is right do a "SetStage()" to stop the fighting?
User avatar
Emily Graham
 
Posts: 3447
Joined: Sat Jul 22, 2006 11:34 am

Post » Thu Jun 21, 2012 2:39 pm

No need for that. With StartFistfight and StopFistfight functions in your quest script you can simply put a call to
RegisterForSingleUpdate(20)
at the end of StartFistfight(), and then give your quest script an OnUpdate() event like this


Event OnUpdate()   StopFistfight()EndEvent

I can promise you it works ;)
User avatar
Amanda Furtado
 
Posts: 3454
Joined: Fri Dec 15, 2006 4:22 pm

Next

Return to V - Skyrim