Jump to content

Having trouble changing GlobalVariable


Recommended Posts

So, I'm brand new to scripting, and it's REALLY not wanting to be kind to me.

 

Basically, I'm just trying to have a script that can be called on by papyrus fragments to modify a global variable up or down. I figured it would be easy, but everything I do fails.

Most recently, the issue I've been running into is defining the global property at the beginning. If I only have...

 

Scriptname MyScript extends Quest

GlobalVariable Property MyGlobal Auto
It fails every time, saying "cannot name a variable or property the same as a known type or script". I don't know why this is so tricky for me, but it really is. If someone could just let me know how I'd go about modifying a global up and down, that would be fantastic
Link to comment
Share on other sites

Change the name. Can't use "MyGlobal", thats what it's telling you.

 

You can also change global in fragment if you don't want to make new script for it. This can be in dialogue or in stage. (and Yes, they can be fired multiple times with setStage even when current stage doesn't change).

 

You can just do:

mahGlobal.SetValue(1)

and make property named mahGlobal first.

Link to comment
Share on other sites

Change the name. Can't use "MyGlobal", thats what it's telling you.

 

You can also change global in fragment if you don't want to make new script for it. This can be in dialogue or in stage. (and Yes, they can be fired multiple times with setStage even when current stage doesn't change).

 

You can just do:

mahGlobal.SetValue(1)

and make property named mahGlobal first.

I was just using "myGlobal" as an example, it's not actually named that. I've actually named it a bunch of different things cause I thought that was the issue, and none of them worked. And I was actually wanting to add/subtract numbers from it, not just set it. Is that possible?

 

EDIT: And now I tried exactly what you said, copy/pasting what you wrote (but changing the global name to mine) and it tells me

"setvalue is not a function or does not exist"

"cannot call the member function setvalue alone or on a type, must call it on a variable"
I'm sure it's just something stupid that I'm missing, but I'm really having the hardest time with this. The art side of things really is my strong suit.
Edited by sgtmcbiscuits
Link to comment
Share on other sites

Yes, you can do this for example:

GlobalTest.SetValue(someRandomFloat / 2 + 4 * 8 - 14 + GlobalTest.GetValue())

GlobalVariable Property GlobalTest Auto Const
float someRandomFloat

or you can just do:

GlobalTest.SetValue(GlobalTest.GetValue() + 1)

or you can do:

float tempFloat = GlobalTest.GetValue()

tempfloat = tempFloat + 100 ; or do more stuff here

GlobalTest.SetValue(tempfloat)

You need to post your whole script you have problems with. Just post your script you are trying to do :smile:

Link to comment
Share on other sites

 

You need to post your whole script you have problems with. Just post your script you are trying to do :smile:

 

I have literally nothing. Like I said, I'm pretty much a complete beginner. I copy pasted one script before to make a quest wait a certain amount of time before progressing, watched a couple YouTube tutorials, and that's it.

 

As far as I can tell, I have to declare the global as a property(?) in the beginning of the script. I use "GlobalVariable Property Kimberly Auto", and it gives me errors for just doing that. I can't for the life of me figure this out.

Link to comment
Share on other sites

Hmm, so does your script compile if you do this?

Scriptname JustTestingDeleteLater extends Quest

GlobalVariable Property KimberlyGlobal Auto

if you try do this it won't compile:

Scriptname JustTestingDeleteLater extends Quest

GlobalVariable Property KimberlyGlobal Auto

KimberlyGlobal.SetValue(1)

because the script doesn't know when to do that SetValue.

 

Instead you need to have event or function to do it and call that function from somewhere(or have event fire), for example:

Scriptname JustTestingDeleteLater extends Quest

GlobalVariable Property KimberlyGlobal Auto


Event OnStageSet(int auiStageID, int auiItemID) ;int auiStageId is the stage that was set
	if(auiStageID == 50) ; if its stage 50 lets set global
		KimberlyGlobal.SetValue(1)
		Debug.Notification("stage 50, setting global!")
	endIf
endEvent

But first, does the first example work on you? It compiles if you copy all but NOT the script name line to your script, that you made in ck using Add -> [new script]? (in your quest window).

Link to comment
Share on other sites

That first one DID compile! Do I need to append the word "Global", like you did? Or was that for testing purposes? Currently, I just wrote out...

Scriptname JustTestingDeleteLater extends Quest

GlobalVariable Property KimberlyGlobal Auto

Function Test()
KimberlyGlobal.SetValue(1)
EndFunction

And it compiles successfully. Basically, here's what I'm asking. If I have a global variable called "Kimberly", will this script change it's value to 1? Or will it change a global called "KimberlyGlobal" to 1?

I ask because whenever I used "GlobalVariable Property Kimberly Auto", it would fail, saying I can't make it the same name as something else (or something along those lines). I want to make sure it's changing the global that I made, not some new one it creates or something.

 

Sorry for all the questions, I just began and I'm really having trouble, and you're the first one that's really been able to help!

Link to comment
Share on other sites

You've created a function that will set the value of KimberlyGlobal to 1.000... (a float). However, you still need to define an event in which this function will be run.

 

For example, if you want to run this function when the quest that the script's attached to initialises, you'll want to add the following:

Event OnInit()
    Test()
EndEvent

Just because something compiles, it doesn't mean that it's going to do what you want it to do.

 

So basically, you'll have a script that's attached to a quest that looks like this:

ScriptName JustTestingDeleteLater Extends Quest

; ==========
; Properties
; ==========

GlobalVariable Property KimberlyGlobal Auto Const Mandatory

; ======
; Events
; ======

Event OnInit()
    Debug.Notification(asNotificationText = "KimberlyGlobal = " + KimberlyGlobal) ; This should display "KimberlyGlobal = 0", assuming a default value of 0
    
    Test()
    
    Debug.Notification(asNotificationText = "KimberlyGlobal = " + KimberlyGlobal) ; This should display "KimberlyGlobal = 1"
EndEvent

; =========
; Functions
; =========

Function Test()
    KimberlyGlobal.SetValue(1 As Int)
EndFunction

Assuming that the quest starts with the game, and you want to change the value of the global variable when the user first loads the mod, this will function as intended.

 

You'll want to look at the various events you can use if this isn't what you want (where some events require you to attach the script to the relevant ObjectReference, Location, etc.)

 

Also, make sure that you've set your properties up properly. I quite frequently forget to open up the Properties window to establish each of the properties I've defined in the script, and spend ages trying to see what's wrong.

Link to comment
Share on other sites

The name should not matter at all actually(unless it's something the CK wont let you use for some reason).

 

It could be "GlobalVariable Property xDLOL Auto".. which global it affects depends on this: Go to your quest -> Scripts, you see your script name, click on it, press Properties and then you just click on the property, select object "YourGlobalName" from the list and that is the global it's gonna change. Press OK to finish.

 

Now, for your function to work, you can go to stage or dialogue, anything with Fragment. Then:

 

1. see kmyQuest -> select the script you just made, and in the fragment write:

kmyQuest.Test()

and it will do that function for you when the fragment is run. It can be in dialogue or quest stage.

 

Now, if you want to make your function better, do this:

Scriptname JustTestingDeleteLater extends Quest

GlobalVariable Property KimberlyGlobal Auto

Function Test(float fNumberToSet)
KimberlyGlobal.SetValue(fNumberToSet)
EndFunction

then, in the fragment you can do:

kmyQuest.Test(10)

and it will set the global to 10.

 

Or, if you want to add to that number you can do this:

Scriptname JustTestingDeleteLater extends Quest

GlobalVariable Property KimberlyGlobal Auto

Function Test(float fNumberToSet)
KimberlyGlobal.SetValue(KimberlyGlobal.GetValue()+ fNumberToSet)
EndFunction

Then, in fragment when you do:

kmyQuest.Test(2)

it will add 2 to the total number. Hope this helps.

Link to comment
Share on other sites

You've created a function that will set the value of KimberlyGlobal to 1.000... (a float). However, you still need to define an event in which this function will be run.

 

Is this necessary if I'm just going to be calling this function from a papyrus fragment in dialogue?

 

The name should not matter at all actually(unless it's something the CK wont let you use for some reason).

 

It could be "GlobalVariable Property xDLOL Auto".. which global it affects depends on this: Go to your quest -> Scripts, you see your script name, click on it, press Properties and then you just click on the property, select object "YourGlobalName" from the list and that is the global it's gonna change. Press OK to finish.

 

Thank you! I never understood how to define the properties! I never put it together that you needed to define it in the script, then go back to the properties window and select your actual variable. That's one of the biggest issues I've been having. Okay, then if that's all I need, I think I'm good. I used your version that enabled me to add amounts, rather than just change it. Quick question, though. If I want to modify it down (subtract), do I need to make a second function, or can I just "add" a negative? For example, if the global is currently set to 10, and in a fragment, I have...

 

kmyQuest.Test(-5)

 

...Will that change the global to 5? Or will I need to make another function, saying...

Function TestSubtract(float fNumberToSet)
KimberlyGlobal.SetValue(KimberlyGlobal.GetValue()- fNumberToSet)
EndFunction

And call it using kmyQuest.TestSubtract(5)? Or will either way work?

Link to comment
Share on other sites

  • Recently Browsing   0 members

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