Head-scratching script oddness.

Post » Sat Nov 17, 2012 5:59 am

debug.notification("x: " + pc.getpositionx())pc_oldpos[0] = pc.getpositionx()debug.notification("x: " + pc_oldpos[0])

And the output:

x: -9378._x: -54003._

The array is a property, declared as such:

float[] property pc_oldpos autoevent oninit()	 pc_oldpos = new float[3]endevent

Please help. I'm at my wit's end.
User avatar
Lucky Girl
 
Posts: 3486
Joined: Wed Jun 06, 2007 4:14 pm

Post » Sat Nov 17, 2012 1:00 am

And the output:

x: -9378._x: -54003._

Please help. I'm at my wit's end.

I'm not seeing that behavior. I'm getting what I would expect to see with X being the same in both calls. I used your property declaration and OnInit() code as you provided, but modifed the main code as follows:
 debug.notification("x: " + game.GetPlayer().getpositionx()) pc_oldpos[0] = game.GetPlayer().getpositionx() debug.notification("xx: " + pc_oldpos[0])
I assumed PC = Player Character so you can see what I did there. The x and xx was obviously just for display purposes, but since both lines read exactly the same, this was easier to read.
User avatar
Lauren Dale
 
Posts: 3491
Joined: Tue Jul 04, 2006 8:57 am

Post » Sat Nov 17, 2012 3:49 am

Nothing jumps out at me... at least not with out more context. The script property (auto) actually translates into a set and get method with parameters placed on your script. So your seemingly simply assignment operation is actually gets compiled into a much more complex and lengthy operation than it appears in the code. For testing purposes, you might want to try declaring and using a local float array and see if that changes anything.

Also... what is invoking this method? If the method is invoked as a result of an OnLocationChange event attached to an NPC, you would be in the middle of crossing cell boundaries. The x/y coordinates of each cell are independant... thus with enough delay (say an expensive set/get operation on the script) you could actually see a different value returned by 2 consequtive calls to the getpositionx() method. I am just thinking out loud. Why code that looks like it should work might not..
User avatar
Sarah Knight
 
Posts: 3416
Joined: Mon Jun 19, 2006 5:02 am

Post » Fri Nov 16, 2012 10:49 pm

The script is attached to a quest player alias. pc is indeed the player actor. The event is onPlayerBowShot. The 2nd value in the output is actually the correct one, which is even more baffling. Replacing pc with game.getplayer() solved it though, which is odd seeing as I had assigned pc to game.getplayer().

These sort of things are extremely frustrating for a beginner such as myself :/. I've wasted too much time with these mysterious errors.
User avatar
Charlie Ramsden
 
Posts: 3434
Joined: Fri Jun 15, 2007 7:53 pm

Post » Sat Nov 17, 2012 10:01 am

Another head-scratching puzzle for ya:

scriptname perkyperk extends perkglobalvariable property x autofloat fevent onplayerbowshot...    f = game.getplayer().getpositionx()    debug.notification("f: " + f)    x.setvalue(f)    debug.notification("x: " + x.getvalue())endevent

The property is pointing to the correct globalvariable.

Output:

f: -54003._x: 0.000000

WTF dudes?
User avatar
Marcus Jordan
 
Posts: 3474
Joined: Fri Jun 29, 2007 1:16 am

Post » Sat Nov 17, 2012 11:46 am

The property is pointing to the correct globalvariable.

Output:

f: -54003._x: 0.000000

What "type" of global is x? Short, long float? Did you make sure it's not a constant?

I have come across seemingly crazy behavior with the CK/Papyrus (and I'm not new to coding) and many times I really thought something was a bug. Most of the time though, I found the problem was between the keyboard and the chair. Fortunately, I'm stubborn and I could usually track down the problem and most of the time, it actually made sense. I have never found random craziness with Papyrus though, nothing like the issues you have been experiencing. I'm not saying there aren't any bugs, just usually it ended up making sense.
User avatar
Danger Mouse
 
Posts: 3393
Joined: Sat Oct 07, 2006 9:55 am

Post » Sat Nov 17, 2012 12:44 am

What "type" of global is x? Short, long float? Did you make sure it's not a constant?

I have come across seemingly crazy behavior with the CK/Papyrus (and I'm not new to coding) and many times I really thought something was a bug. Most of the time though, I found the problem was between the keyboard and the chair. Fortunately, I'm stubborn and I could usually track down the problem and most of the time, it actually made sense. I have never found random craziness with Papyrus though, nothing like the issues you have been experiencing. I'm not saying there aren't any bugs, just usually it ended up making sense.

It's a non-constant float.

It dawned on me that all this scripting weirdness only began when I started using the onplayerbowshot event. So I tried this code instead to see what would happen:

scriptname perkyperk extends perkglobalvariable property x autofloat fevent oninit()registerforanimationevent(game.getplayer(), "BowRelease")endeventevent onanimationevent...    f = game.getplayer().getpositionx()    debug.notification("f: " + f)    x.setvalue(f)    debug.notification("x: " + x.getvalue())endevent

Lo and behold, everything worked as expected. So it's the onplayerbowshot event that is doing funky things, but why? How can an event change the language's basic functionality? And are there more such events that cause weird side-effects?
User avatar
Life long Observer
 
Posts: 3476
Joined: Fri Sep 08, 2006 7:07 pm

Post » Sat Nov 17, 2012 4:34 am

I've seen strange behavior with parenthetical variables. What I started doing is to set everything to a temp variable first, then call that temp variable in the parenthesis.

example:
float tempPosX = blahBlah.getPositionX()
debug.notification("xPos" + tempPosX)

another example:
float tempSin = math.sin(tempAng)
debug.notification("Sin" + tempSin)
[instead of notif("Sin" + math.sin(tempAng))]

The main point is that doing certain functions while nested may not work properly and may even return warnings/errors. Then there's the possibility as someone said above, that the values are simpy changing from moment to moment depending on when that function is ACTUALLY run (especially on fast-moving objects and getPos).

[EDIT: then of course, the onBowShot thing is a new function and may be bugged... wouldn't surprise me.]
User avatar
Riky Carrasco
 
Posts: 3429
Joined: Tue Nov 06, 2007 12:17 am

Post » Sat Nov 17, 2012 1:53 pm

I've seen strange behavior with parenthetical variables. What I started doing is to set everything to a temp variable first, then call that temp variable in the parenthesis.

As crazy as that sounds (at least to me), I have found that to be true also. It's a habit from C# coding that I always use paranthesis for my IF/THEN statements, but I'm learning not to do that in Papyrus.
User avatar
Dewayne Quattlebaum
 
Posts: 3529
Joined: Thu Aug 30, 2007 12:29 pm

Post » Sat Nov 17, 2012 3:42 am

Now I have another problem, but this time it's likely because of my own ignorance. I'm trying to access the global variable in the perkyperk script from another script (activemagiceffect attached to an npc). Is this the correct way to do this?

scriptname magickymagic activemagiceffectperkyperk property data autofloat fevent onhit...	f = data.x.getvalue()endevent

When I do this, f will always have the value 0. The data property points to the perkyperk script. edit: actually, it's pointing to the perk that perkyperk is attached to. Could this be the problem?
User avatar
Johanna Van Drunick
 
Posts: 3437
Joined: Tue Jun 20, 2006 11:40 am

Post » Sat Nov 17, 2012 4:17 am

Instead of "perkyPerk property.." it should be "globalVariable property data auto" - BUT I would change "data" to something more unique like, 'perkyData'. the word "data" may be reserved by the game-engine/Papyrus to do stuff in particular. That should also be global variable that is created in the objectWindow, under "misc/global". It doesn't matter which script accesses it, so you don't need to reference those scripts from others.. just that global. Now if you wanted to access a script variable from another script, that's a different story.

[EDIT: but yea.. that's how you access the global, by doing the "f = perkyData.getValue()". You may not have to set it 'f', but as stated above, sometimes the extra step is good to take.. especially since it doesn't take any noticably extra time to run (unless you do it a thousand times, but once in an onHit is no problem).]
User avatar
Robert DeLarosa
 
Posts: 3415
Joined: Tue Sep 04, 2007 3:43 pm

Post » Sat Nov 17, 2012 5:56 am

float f

When I do this, f will always have the value 0. The data property points to the perkyperk script. edit: actually, it's pointing to the perk that perkyperk is attached to. Could this be the problem?

This is the syntax for a global property:
GlobalVariable Property fGlobal Auto

It's not a float type, even if that's the data type you indicated in the CK, it's a type GlobalVariable. You then need to use .GetValue() and .SetValue() and use "as float", so:
float f = fGlobal.GetValue() as float
User avatar
Nicholas C
 
Posts: 3489
Joined: Tue Aug 07, 2007 8:20 am

Post » Sat Nov 17, 2012 6:31 am

I use globals extensively in my Gokstad sailing mod, but I never cast anything as a float - so that may be an extra step. As long as the local variable (f in this case) is defined the same as the global (both floats) they should work without specially casting anything. One difference that may require that casting though, is that in my mods I always define all my variables at the top (not inside the code, like "float f = blah.getValue()"). I always define "float f" then in the code all I have to do is "f = ...".
User avatar
I love YOu
 
Posts: 3505
Joined: Wed Aug 09, 2006 12:05 pm

Post » Sat Nov 17, 2012 1:19 am

Hmm, I thought I needed to access the script where the global variable x was declared (in the perkyperk script. BTW these are just joke names I came up with for my example code :P).

Declaring it again in the magickymagic script didn't solve anything. f will still always be set to 0. Posting both scripts now in case there is any confusion:

scriptname perkyperk extends perkglobalvariable property x autofloat fevent oninit()registerforanimationevent(game.getplayer(), "BowRelease")endeventevent onanimationevent...    f = game.getplayer().getpositionx()    debug.notification("f: " + f)    x.setvalue(f)    debug.notification("x: " + x.getvalue())endevent

scriptname magickymagic activemagiceffect;/perkyperk property data autothis is how I thought it should work/;globalvariable property x autofloat fevent onhit...	    f = x.getvalue()endevent
User avatar
Rik Douglas
 
Posts: 3385
Joined: Sat Jul 07, 2007 1:40 pm

Post » Sat Nov 17, 2012 1:13 pm

The global has to be declared in any script that references it. But it sounds like you haven't created the ACTUAL global.. as I said above, you do that in the objectWindow under "miscellaneous" and "global". You have to r-click and create a new one, click the type (float/etc), then type the name and value (if any). Also make sure you leave "constant" alone.

You ALSO have to fill the properties of the script on whatever object/ref you attach it to, or that global will remain blank (your "0" by default). I suggest checking your Papyrus log for errors as well - to ensure nothing else is interfering or going wrong.
User avatar
lilmissparty
 
Posts: 3469
Joined: Sun Jul 23, 2006 7:51 pm

Post » Sat Nov 17, 2012 1:13 am

	f = game.getplayer().getpositionx()	debug.notification("f: " + f)	x.setvalue(f)	debug.notification("x: " + x.getvalue())
Assuming your second debug showed the correct value. Did you make sure you are setting the global property in BOTH scripts? (I would double check again...)
User avatar
Milad Hajipour
 
Posts: 3482
Joined: Tue May 29, 2007 3:01 am

Post » Sat Nov 17, 2012 5:11 am

The global has to be declared in any script that references it. But it sounds like you haven't created the ACTUAL global.. as I said above, you do that in the objectWindow under "miscellaneous" and "global". You have to r-click and create a new one, click the type (float/etc), then type the name and value (if any). Also make sure you leave "constant" alone.

You ALSO have to fill the properties of the script on whatever object/ref you attach it to, or that global will remain blank (your "0" by default). I suggest checking your Papyrus log for errors as well - to ensure nothing else is interfering or going wrong.

Of course I created the global ^^. I'll check the log for errors. edit: no errors

Assuming your second debug showed the correct value. Did you make sure you are setting the global property in BOTH scripts? (I would double check again...)

Yup, both properties are pointing to the same global.
User avatar
benjamin corsini
 
Posts: 3411
Joined: Tue Jul 31, 2007 11:32 pm

Post » Sat Nov 17, 2012 3:30 am

In that last code you posted, was it the f or the x that returns 0? If you are actually using the "x", then that may be the problem. X is a function which is a shortcut for "getPositionX"... so that may be interfering somehow. And you're sure you filled the properties after attaching the script? It wouldn't return an error for unfilled properties, just return 0 or None.

If all that's in order though, try inserting a utility.wait(0.3whatever) between the getPos and the notif (or between filling a variable then calling it back). Some functions take a bit of time to register.
User avatar
Ann Church
 
Posts: 3450
Joined: Sat Jul 29, 2006 7:41 pm

Post » Sat Nov 17, 2012 12:29 am

In that last code you posted, was it the f or the x that returns 0? If you are actually using the "x", then that may be the problem. X is a function which is a shortcut for "getPositionX"... so that may be interfering somehow. And you're sure you filled the properties after attaching the script? It wouldn't return an error for unfilled properties, just return 0 or None.

If all that's in order though, try inserting a utility.wait(0.3whatever) between the getPos and the notif (or between filling a variable then calling it back). Some functions take a bit of time to register.

Everything works perfectly in the first script. The second script, which is attempting to read the global variable which was properly set in the first script, isn't.

I'm not using variables named x in my actual script.

I'll try and see if the global variable can be properly read by the condition system. edit: yup, it works fine there.
User avatar
Eileen Collinson
 
Posts: 3208
Joined: Thu Dec 28, 2006 2:42 am

Post » Sat Nov 17, 2012 1:11 am

Everything works perfectly in the first script. The second script, which is attempting to read the global variable which was properly set in the first script, isn't.

I'm not using variables named x in my actual script.

I'll try and see if the global variable can be properly read by the condition system. edit: yup, it works fine there.

You can also check the global variable using the SHOW console command: Show

When I post code questions, I'll often make a new function for the test so that I can post the actual code... sometimes I find the problem in that process ;) I don't see a problem with what you are posting, but since it's not what you're using, it's hard to say where the problem lies.
User avatar
El Khatiri
 
Posts: 3568
Joined: Sat Sep 01, 2007 2:43 am

Post » Sat Nov 17, 2012 2:56 pm

Mystery solved. I'll chalk this one down to exhaustion from the onplayerbowshot bug.

What was happening was that the magickymagic script was added dynamically, using this http://www.creationkit.com/Dynamically_Attaching_Scripts. Because I wanted to test things quickly, I saved right in front of a bear. Unfortunately, it didn't occur to me that the effect that was applied on the bear would be saved along with him. All the subsequent changes I made to the script were being ignored because the effect to which the script was attached was not being reapplied to the bear.

I fast traveled to a new location, found a new target, and everything worked as expected.

:blush:

onplayerbowshot is bugged however, as that script was on the player and had nothing to do with the dynamically attached script.
User avatar
Alan Cutler
 
Posts: 3163
Joined: Sun Jul 01, 2007 9:59 am


Return to V - Skyrim