Getting a Script to Correctly Return a Global Value

Post » Mon Jun 18, 2012 1:40 pm

I've spent the past few days struggling with Papyrus. I'm trying to make a script that ties the transformations of a werewolf to the moon, and mostly failing, and I've managed to track down the reason, using debug functions, to the Global Variables I'm referencing in the script (it's a quest script), in this case PlayerIsWerewolf, GameHour, and GameDaysPassed; No matter what I do or how I change the script, all of the global variables return as 0. No matter what I do, how I change the script, or what I do with the properties, they won't return as anything other than zero, as evidenced by a notification I put in the script that returns the value of the property recording GameHour ( TimeOfDay ) every second; it doesn't change at all.

I'm positive the script is actually running, since the notification always comes in, and otherwise it seems to be running as intended, excluding of course everything that's dependent on the global variables.

If anyone has found a way to get a script to return the actual value of a global variable, I'd very much appreciate your help. I looked through the wiki, double checked my syntax, everything I could think of, and still its not working.

PS: Before you ask, I configured the script's properties in the property window to reference the correct variables, so that's not the problem, though I initially thought it was.
User avatar
Batricia Alele
 
Posts: 3360
Joined: Mon Jan 22, 2007 8:12 am

Post » Mon Jun 18, 2012 1:41 am

PS: Before you ask, I configured the script's properties in the property window to reference the correct variables, so that's not the problem, though I initially thought it was.
You definitely need to do that, although Auto fill will do that for you.

To access a Global, you need to define it:
GlobalVariable Property ImsixyAndIKnowIt auto
Assuming 'ImsixyAndIKnowIt' is exists (vanilla or user-made global) it will be populated for the script.
User avatar
Chris BEvan
 
Posts: 3359
Joined: Mon Jul 02, 2007 4:40 pm

Post » Mon Jun 18, 2012 12:25 pm

^ I did both of those. If nothing else is wrong there, then I'm guessing that means that there's something wrong with the way I referenced the global variables in the actual script. Sorry if I phrased it wrong, but I did auto fill it in the properties menu.

Basically I put

TimeOfDay == Gamehour.Getvalue()

and then as the debug notification, some time later in the script.

debug.notification(TimeOfDay)


If it was working properly, I imagine TimeOfDay would be returning as well, whatever time it is.

I was looking at some of the Bethesda scripts, and I noticed that instead of Global.Getvalue()

they used Global.value

Would that be what I'm missing?
User avatar
Nicole Kraus
 
Posts: 3432
Joined: Sat Apr 14, 2007 11:34 pm

Post » Mon Jun 18, 2012 5:21 am

It would be worth trying, although looking at the http://www.creationkit.com/GlobalVariable_Script documentation you'll be able to see that "value" is a float property (meaning it can be read by other scripts), whereas the function "GetValue" is simply a function that returns the value stored in the property "value". The two methods should work essentially identically.

Cipscis
User avatar
Lilit Ager
 
Posts: 3444
Joined: Thu Nov 23, 2006 9:06 pm

Post » Mon Jun 18, 2012 12:29 pm

Just tried it. Not working. I think maybe I'll just create an extremely script solely to return a random global value, get that working, and figure out what's wrong.

ScriptName PlayingWithGlobalsGlobalVariable Property GameHour autoEvent OnUpdate()if GameHour.Value != 0debug.notification("Global Has Returned as Non-zero value.")elsedebug.notification("Global Has Returned as zero.")endifend


The papyrus fragment in the PlayingWithGlobals quest is simply

RegisterForUpdate(1)

Okay, why isn't it letting me make a Papyrus fragment?
User avatar
George PUluse
 
Posts: 3486
Joined: Fri Sep 28, 2007 11:20 pm

Post » Mon Jun 18, 2012 8:29 am

ScriptName PlayingWithGlobals extends Quest
User avatar
Adam Porter
 
Posts: 3532
Joined: Sat Jun 02, 2007 10:47 am

Post » Mon Jun 18, 2012 3:36 am

ScriptName PlayingWithGlobals extends Quest

Heh, yeah figured that one out when it refused to compile "registerForUpdate", on the plus side, it might actually be working.
User avatar
Dominic Vaughan
 
Posts: 3531
Joined: Mon May 14, 2007 1:47 pm

Post » Mon Jun 18, 2012 10:40 am

And it WORKS!!! Now to figure out what it was in my script that caused things to go wrong...

Edit: I noticed something perculiar: For some reason, every so often, it would spam me with a zero in the notification area, despite the fact that this script was literally the only one running on that quest and the only thing I changed.
User avatar
Samantha Mitchell
 
Posts: 3459
Joined: Mon Nov 13, 2006 8:33 pm

Post » Mon Jun 18, 2012 1:29 pm

Damnit damnit damnit damnit. As soon as I waited, everything exploded. It just derps around at approximately 17 (GameHour.value) that is. Methinks there might be some bugs that Bethesda just didn't care about.
User avatar
Matthew Aaron Evans
 
Posts: 3361
Joined: Wed Jul 25, 2007 2:59 am

Post » Mon Jun 18, 2012 1:21 am

do you save the GameHour.value to a local variable ?
User avatar
^_^
 
Posts: 3394
Joined: Thu May 31, 2007 12:01 am

Post » Mon Jun 18, 2012 1:21 pm

Nope, I didn't, and I imagine that was the issue the original script had, wasn't it?

Anyhow, it actually seems to be working, except that its not returning the (It's after 8) notification I want it to.
User avatar
Laura Samson
 
Posts: 3337
Joined: Wed Aug 29, 2007 6:36 pm

Post » Mon Jun 18, 2012 6:44 am

can you post your current code here :P Gonna test it in the CK myself.
User avatar
Natalie Taylor
 
Posts: 3301
Joined: Mon Sep 11, 2006 7:54 pm

Post » Mon Jun 18, 2012 4:57 am

How odd. So Global Values can be read/written when extending from a Quest but not when extending from ActiveMagicEffect?
User avatar
Astargoth Rockin' Design
 
Posts: 3450
Joined: Mon Apr 02, 2007 2:51 pm

Post » Mon Jun 18, 2012 1:11 pm

can you post your current code here :tongue: Gonna test it in the CK myself.

Sure thing...Hmm Let's see

It was

Scriptname cohMoonPhaseScript extends Quest  GlobalVariable Property GameHour autoEvent OnInit()RegisterForUpdate(1)EndEventEvent OnUpdate()if GameHour.Value >= 20debug.notification("It's after eight")elsedebug.notification(GameHour.Value)endifEndEvent

I'm not sure if the is the fact that its spamming notifications so fast that its bogging down the script, but something's not working the way it should. Then again, maybe I should have the time of day return every 5 seconds instead of every one second.
User avatar
Markie Mark
 
Posts: 3420
Joined: Tue Dec 04, 2007 7:24 am

Post » Mon Jun 18, 2012 10:44 am

Ah, I see my problem. I didn't know I had to go over to Miscellaneous and create a Global variable in the "Global" section. So I was referencing a Global that didn't exist.
User avatar
Minako
 
Posts: 3379
Joined: Sun Mar 18, 2007 9:50 pm

Post » Mon Jun 18, 2012 5:08 am

Scriptname WarewolfTransformation extends Quest Hidden{Transform god damit !!!}import debugGlobalVariable Property GameHour autoEvent OnInit()  debug.notification("Updating register !!!")  RegisterForUpdate(5)EndEventEvent OnUpdate()  if GameHour.Value >= 20	debug.notification("It's after eight")  else	debug.notification("its = " + GameHour.Value)  endifEndEvent

works like a charm. I noticed it notified me two times that the script got registered so it means the "start game enabled" counts like an event Oninit()
What might be the case is that I First created the quest named GSQ01 priority 60 event none start game enabled type none then OK
After that I opened it and added a new script >> code that I posted.
Then I saved and compiled , cliked OK.
Opened the quest went to scripts and choosen my scipt properties. Now I saw GlobalHour as an unknown property so I clicked auto-fill and saved.
After this is started to work, didnt work before I used the auto-fill.
User avatar
loste juliana
 
Posts: 3417
Joined: Sun Mar 18, 2007 7:37 pm

Post » Sun Jun 17, 2012 10:57 pm

works like a charm. I noticed it notified me two times that the script got registered so it means the "start game enabled" counts like an event Oninit()
I brought this up in testing, here's the explanation I was given (SmkViper is a developer):
OnInit is run when an object first becomes scripted and will run whenever an object is reset (since a reset clears all your properties and variables back to their initial values).

So what you’re seeing is the quest being created and the script attached running OnInit, then the game starting up the quest (since it starts enabled), which, because the quest can run more than once, will reset the script and re-run the OnInit event.

As far as your script can tell, it’s only been run once, but external systems (in this case, the message box) are getting two commands. You would see the same thing for any scripts attached to aliases on that quest, since they initialize and reset at the same time the quest does.

Cipscis
User avatar
meghan lock
 
Posts: 3451
Joined: Thu Jan 11, 2007 10:26 pm

Post » Mon Jun 18, 2012 4:44 am

^^ Die by sword: Still thinks its whatever time the script started at, which in my case is never between eight and midnight.

Edit: Or rather, that's what the debug notification's saying, though considering its OnUpdate(), it's probably taking each and every hour into accommodation. Perhaps it should send the message if and only if its in the correct time interval?

Btw, is there any reliable way to check what the value ACTUALLY is?
User avatar
casey macmillan
 
Posts: 3474
Joined: Fri Feb 09, 2007 7:37 pm

Post » Mon Jun 18, 2012 12:43 am

^^ Die by sword: Still thinks its whatever time the script started at, which in my case is never between eight and midnight.

Edit: Or rather, that's what the debug notification's saying, though considering its OnUpdate(), it's probably taking each and every hour into accommodation. Perhaps it should send the message if and only if its in the correct time interval?

Btw, is there any reliable way to check what the value ACTUALLY is?

Well I was sitting there from 3 pm to 8 pm and it notified me every 5 sec about the current time and once it hit 8 pm to 11:59pm it said "It's after eight"
You can see the actual value in Miscelanous->Global->GlobalHour
User avatar
Cayal
 
Posts: 3398
Joined: Tue Jan 30, 2007 6:24 pm

Post » Mon Jun 18, 2012 11:44 am

Well that's good. For some reason I keep getting random spams of the current time in float form with no "It's (x) time", though that may be an artifact of another script that I made in this plugin.
User avatar
Chloe Yarnall
 
Posts: 3461
Joined: Sun Oct 08, 2006 3:26 am

Post » Mon Jun 18, 2012 11:39 am

Well, it looks like things are working, though now that I've moved onto the next step I'm getting a similar problem: When I try to set a global value when the conditions (in this case hours between 8 PM and 9 AM) clear, in this case a custom global, "cohTransformationsAllowed", it doesn't work. I've verified this with the console command GetGlobalValue...

Do I need to import the global value script functions in order to Set global values?

Edit: Herpaderp, I may have forgotten to define cohTransformationsAllowed in the properties menu.

Here's the script as of now...I'm still getting a mysterious spam of the game hour function at intervals of one second though...Oh herpaderp, forgot to disable the other .esp I was using...And yet the clockspam continues.
Scriptname cohMoonPhaseScript extends Quest Hidden{Not Done Yet}import debugGlobalVariable Property cohTransformationsAllowed autoGlobalVariable Property GameHour autoEvent OnInit()  RegisterForUpdate(5)EndEventEvent OnUpdate()  if GameHour.Value >= 20 || GameHour.Value < 5cohTransformationsAllowed.SetValue(1)  elsecohTransformationsAllowed.SetValue(0)  endif  if cohTransformationsAllowed.Value =http://forums.bethsoft.com/topic/1345214-getting-a-script-to-correctly-return-a-global-value/= 1debug.notification("Transformations Are Allowed!")endifEndEvent
User avatar
Rachel Hall
 
Posts: 3396
Joined: Thu Jun 22, 2006 3:41 pm

Post » Sun Jun 17, 2012 11:03 pm

Scriptname WerewolfTransformation extends Quest Hidden{Controls the Timing for transformation.}import debugimport Mathint  property cohCanTransform autoSpell property WerewolfChange autoGlobalVariable Property GameHour autoGlobalVariable Property GameDaysPassed autoGlobalVariable Property PlayerIsWerewolf autoGlobalVariable Property PlayerWerewolfShiftbacktime autoMagicEffect Property WerewolfChangeEffect autoEvent OnInit()  debug.notification("Updating register - Warewolf active !!!")  RegisterForUpdate(20)EndEventEvent OnUpdate(); Determining Moon Phase Below...Not yet implimented.  int timeOfDay = GameHour.GetValueint()  int DaysPassed = GameDaysPassed.GetValueint(); Ignore PhaseDay, not functioning in this iteration of the script.if timeOfDay >= 20 || timeOfDay <= 6  debug.notification("It's after eight")  cohCanTransform = 1else  debug.notification("its = " + timeOfDay + " o`clock")  cohCanTransform = 0endifif PlayerIsWerewolf.GetValue() == 1  debug.notification("werewolf")else  debug.notification("no werewolf")endifif game.getplayer().HasMagicEffect(WerewolfChangeEffect) == 1  debug.notification("werewolf effect")else  debug.notification("no werewolf effect")endifif PlayerIsWerewolf.GetValue() == 1 && cohCanTransform == 1 && game.getplayer().HasMagicEffect(WerewolfChangeEffect) == 0  debug.notification("We change into a werewolf now !!!!!")  PlayerWerewolfShiftbacktime.SetValue(10000)  WerewolfChange.Cast(Game.GetPlayer(), Game.GetPlayer())elseif game.getplayer().HasMagicEffect(WerewolfChangeEffect) == 1 && cohCanTransform == 0  PlayerWerewolfShiftbacktime.SetValue(1)  game.getplayer().DispelSpell(WerewolfChange)  debug.notification("We change back into our orginal race now !!!!!")else  debug.notification("Buisness as usual  !!!!!")endifEndEvent

Everything works except when it goes into transformation time :tongue: the warewolf change dosnt happen.
After looking into Spell category I found WerewolfChange (power) and WereWolfchangeFX (spell) so the syntax might be wrong here.

WerewolfChange.Cast(Game.GetPlayer(), Game.GetPlayer())
User avatar
Queen
 
Posts: 3480
Joined: Fri Dec 29, 2006 1:00 pm

Post » Mon Jun 18, 2012 8:35 am

Yeah, I think it would be better to start the Playerwerewolf transformation quest line and piggyback on the 400 odd line long script from Bethesda that I'm going to have to look through and modify.
User avatar
Cathrine Jack
 
Posts: 3329
Joined: Sat Dec 02, 2006 1:29 am

Post » Mon Jun 18, 2012 7:31 am

Lmao it works :biggrin:
WerewolfChange.Cast(Game.GetPlayer(), Game.GetPlayer())
Is the way to go :biggrin:

I fixed the code 2 post above :biggrin: Copy/paste into your quest script and test it :biggrin: Hilarious when I transformed next to the jarl in Dragonsreach.
And heres a clean (no debug) code

Scriptname WerewolfTransformation extends Quest Hidden{Controls the Timing for transformation.}int  property cohCanTransform autoSpell property WerewolfChange autoGlobalVariable Property GameHour autoGlobalVariable Property GameDaysPassed autoGlobalVariable Property PlayerIsWerewolf autoGlobalVariable Property PlayerWerewolfShiftbacktime autoMagicEffect Property WerewolfChangeEffect autoEvent OnInit()  RegisterForUpdate(20)EndEventEvent OnUpdate(); Determining Moon Phase Below...Not yet implimented.  int timeOfDay = GameHour.GetValueint()  int DaysPassed = GameDaysPassed.GetValueint(); Ignore PhaseDay, not functioning in this iteration of the script.if timeOfDay >= 20 || timeOfDay <= 6  cohCanTransform = 1else  cohCanTransform = 0endifif PlayerIsWerewolf.GetValue() == 1 && cohCanTransform == 1 && game.getplayer().HasMagicEffect(WerewolfChangeEffect) == 0  PlayerWerewolfShiftbacktime.SetValue(10000)  WerewolfChange.Cast(Game.GetPlayer(), Game.GetPlayer())elseif game.getplayer().HasMagicEffect(WerewolfChangeEffect) == 1 && cohCanTransform == 0  PlayerWerewolfShiftbacktime.SetValue(1)  game.getplayer().DispelSpell(WerewolfChange)endifEndEvent
User avatar
Siobhan Wallis-McRobert
 
Posts: 3449
Joined: Fri Dec 08, 2006 4:09 pm

Post » Sun Jun 17, 2012 11:57 pm

What property do I define "werewolf' (the magic effect) as?


Edit: Looks like my scripting engine or something is ACTUALLY broken...That script works for you? For me it doesn't do anything at all.
User avatar
Robert Garcia
 
Posts: 3323
Joined: Thu Oct 11, 2007 5:26 pm

Next

Return to V - Skyrim