Jump to content

Simple Scripting Help


Illustrious

Recommended Posts

I want to attach a script to a piece of dialogue that will change a Global variable. I've spent hours trying to get this simple thing to work and it just won't. Basically all I need a way of calling a function via dialogue. I've been working on SexLab mods on and on for months but using Creation Kit is a complete nightmare. Please help me, I'm so angry right now.

 

By looking at other mods this seems like it should work but it doesn't:

----------------------------------------------------------------------------------------

 

Scriptname SCRIPTNAME Extends TopicInfo Hidden

;BEGIN FRAGMENT Fragment_0
Function Fragment_0(ObjectReference akSpeakerRef)
Actor akSpeaker = akSpeakerRef as Actor
;BEGIN CODE
GLOBALVARIABLE.SetValue(1)
;END CODE
EndFunction
;END FRAGMENT

GlobalVariable Property GLOBALVARIABLE Auto

 

----------------------------------------------------------------------------------------

 

I can get it to change using this, but Event OnInt only seems to work once. If I load another save afterwards it won't trigger the second time.

----------------------------------------------------------------------------------------

 

Scriptname SCRIPTNAME Extends TopicInfo Hidden

 

Event OnInit()

    FunctionName()

EndEvent

Function FunctionName()
   GLOBALVARIABLE.SetValue(1)
EndFunction

GlobalVariable Property GLOBALVARIABLE Auto

Link to comment

Not sure why that particular thing doesn't work as I have not really done much in CK but you could do the increment via function:

Function FunctionX()
    GLOBALVARIABLE += 1
endFunction

Then call it from fragment with:

(GetOwningQuest() as SCRIPTNAME).FunctionX()
Link to comment

Your first script is the correct way to do it.

 

Just check if you defined the property in the script (right click on the script in the Topic Info, select Properties, and fill the value.)

Of course your GLOBALVARIABLE has to be defined in the CK.

 

 

The event OnInit fires only once. So it is not what you are looking for.

 

 

 

To @Tepi, you cannot increase a value of a GlobalVariable object with the operator +=.

It is an object, not an integer.

 

Link to comment

Thank you both for replying. I do have the global variable added as a property to the script.

 

Of course your GLOBALVARIABLE has to be defined in the CK.

 

I'm not sure I fully understand. I created the global varaible before writing the script, is that what you mean? I have it set to 0, short and not a constant. Is that right?
 

Link to comment

Thank you both for replying. I do have the global variable added as a property to the script.

 

Of course your GLOBALVARIABLE has to be defined in the CK.

 

I'm not sure I fully understand. I created the global varaible before writing the script, is that what you mean? I have it set to 0, short and not a constant. Is that right?

 

 

Then you did that all right

Are you editing this script throug right click -> "open source" ? Or are you typing in the small windows for "On dialouge start/ end" ? Because you can only edit script fragments through the windows, not in the source. So your script compiles?

 

the oninit() event trigger once when the script was loaded, so directly when you start the game, even if the quest is not started.

 

Edit: did you click an "properties" and point the property of the GV to the actuall GV?

Link to comment

Thanks for the reply. Yes, I did do the property thing. I've been doing all the scripting in the source because I can't get anything that isn't 'GetOwningQuest().SetStage(10)' to compile in the small End window.

Perhaps I'm not doing the right thing? If you have a moment, could you post a version of my first script that I would need to put in the small window for it to compile without error.

Link to comment

If you have the property of the global variable already set up,

GLOBALVARIABLE.SetValue(1)

is all you need to type in the window for the dialouge start or end.

 

I'm not sure if your scrip will still compile after your changes to the source, so it might be better to start over. Than remove the script, close the dialoug and open it again, then type in the fragment window you want somethin like:

;content

and hit compile. The ; marks everything after is as comment and the compiler ignores it. So you get a fresh new script. Now select the script in the list on the right, click property and set you GV up. 

Now you can delete the ; content again and put the line from the beginning into the fragment window.

That should compile now.

Link to comment
  • 2 months later...

Back again. I'm attempting to adapt Submit for something and have a compilation problem, 'GetActorRef' and 'ForceRefTo' work when I use Submit's original 'ActorBounty1' but not my own. As far as I can tell my references are he same. :/

akSpeaker.StopCombat()
akSpeaker.RemoveFromAllFactions()
akSpeaker.SetRelationshipRank(Game.GetPlayer(), 2)
akSpeaker.AddToFaction(DunPlayerAllyFaction)
akSpeaker.SetFactionRank(DunPlayerAllyFaction, 2)
akSpeaker.SetPlayerTeammate()
akSpeaker.GetActorBase().SetProtected()
akSpeaker.SetAV("Health",1.0)
akSpeaker.AddItem(zilLeatherCuffs, 1)
Game.GetPlayer().RemoveItem(zilLeatherCuffs, 1)
akSpeaker.SetAV("Aggression",0)
akSpeaker.AddToFaction(zilCaptiveFaction)
If ActorCaptive1.GetActorRef() == None
    ActorCaptive1.ForceRefTo(akSpeaker)
Else
    ActorCaptive2.ForceRefTo(akSpeaker)
EndIf

 

Starting 1 compile threads for 1 files...
Compiling "zilCaptiveScript"...
C:\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\zilCaptiveScript.psc(21,17): GetActorRef is not a function or does not exist
C:\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\zilCaptiveScript.psc(22,15): ForceRefTo is not a function or does not exist
C:\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\zilCaptiveScript.psc(24,15): ForceRefTo is not a function or does not exist

No output generated for zilCaptiveScript, compilation failed.

Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on zilCaptiveScript
 

Link to comment

Back again. I'm attempting to adapt Submit for something and have a compilation problem, 'GetActorRef' and 'ForceRefTo' work when I use Submit's original 'ActorBounty1' but not my own. As far as I can tell my references are he same. :/

 

akSpeaker.StopCombat()

akSpeaker.RemoveFromAllFactions()

akSpeaker.SetRelationshipRank(Game.GetPlayer(), 2)

akSpeaker.AddToFaction(DunPlayerAllyFaction)

akSpeaker.SetFactionRank(DunPlayerAllyFaction, 2)

akSpeaker.SetPlayerTeammate()

akSpeaker.GetActorBase().SetProtected()

akSpeaker.SetAV("Health",1.0)

akSpeaker.AddItem(zilLeatherCuffs, 1)

Game.GetPlayer().RemoveItem(zilLeatherCuffs, 1)

akSpeaker.SetAV("Aggression",0)

akSpeaker.AddToFaction(zilCaptiveFaction)

If ActorCaptive1.GetActorRef() == None

    ActorCaptive1.ForceRefTo(akSpeaker)

Else

    ActorCaptive2.ForceRefTo(akSpeaker)

EndIf

 

Starting 1 compile threads for 1 files...

Compiling "zilCaptiveScript"...

C:\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\zilCaptiveScript.psc(21,17): GetActorRef is not a function or does not exist

C:\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\zilCaptiveScript.psc(22,15): ForceRefTo is not a function or does not exist

C:\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\zilCaptiveScript.psc(24,15): ForceRefTo is not a function or does not exist

No output generated for zilCaptiveScript, compilation failed.

 

Batch compile of 1 files finished. 0 succeeded, 1 failed.

Failed on zilCaptiveScript

 

 

look like a property issue for me. Your "ActorCaptive1" and "ActorCaptive2" need to be of the "ReferenceAlias" type.

How do your properties on that script look like?

Link to comment
  • 1 year later...

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use