This has had me stumped for 2 days... Help :

Post » Sat Nov 17, 2012 1:32 pm

I must have tried everything and still do not understand why this is the case but in the below code. The condition is ALWAYS true even when it is CLEARLY not... I don't get it at all and I am so confused! help! What am I doing wrong or missing here?

ATHSthirstValue.SetValue(1.20)PMagicka = Game.GetPlayer().GetActorValuePercentage("Magicka")as floatGMagicka = ATHSthirstValue.getvalue()as floatHMagicka = gMagicka + 0.1if pMagicka > gMagicka  Game.GetPlayer().SetActorValue("MagickaRate", 0)  if PMagicka > HMagicka && HMagicka < 1.0   Debug.MessageBox("Condition True")   Game.GetPlayer().DamageActorValue("Magicka", 1)  endifelseif PMagicka < GMagicka  Game.GetPlayer().SetActorValue("MagickaRate", 0.7)endifUpdateMessage.Show( pMagicka, gMagicka, HMagicka )

PMagicka can never go above 1.0 so how in the heck is it somehow returning a true? HMagicka is 1.3 so how can it POSSIBLY be below 1.0??
This has been driving me insane!

edit: The UpdateMessage.show at the end of the code appears to show all of the correct values.
User avatar
Jessica Phoenix
 
Posts: 3420
Joined: Sat Jun 24, 2006 8:49 am

Post » Sat Nov 17, 2012 6:13 am

I hates && ...

Try it WITHOUT
&& HMagicka < 1.0
And see if it is still true (if it is NOT, then sort out your && clause)
User avatar
meg knight
 
Posts: 3463
Joined: Wed Nov 29, 2006 4:20 am

Post » Sat Nov 17, 2012 8:30 am

I took out the && and just turned it into another if statement within and the condition is still true. I have never had trouble with && before though...
User avatar
abi
 
Posts: 3405
Joined: Sat Nov 11, 2006 7:17 am

Post » Sat Nov 17, 2012 7:10 pm

Your OP is confusing and the code doesn't seem to match... so I really can't answer. I've never had problem with the logical AND (&&) either.

PMagicka can never go above 1.0 so how in the heck is it somehow returning a true? HMagicka is 1.3 so how can it POSSIBLY be below 1.0??
This has been driving me insane!
I'm not following this? Of course you can get a value of 1.3 if it's 130%.
User avatar
Samantha Pattison
 
Posts: 3407
Joined: Sat Oct 28, 2006 8:19 pm

Post » Sat Nov 17, 2012 7:22 am

I must have tried everything and still do not understand why this is the case but in the below code. The condition is ALWAYS true even when it is CLEARLY not... I don't get it at all and I am so confused! help! What am I doing wrong or missing here?

ATHSthirstValue.SetValue(1.20)PMagicka = Game.GetPlayer().GetActorValuePercentage("Magicka")as floatGMagicka = ATHSthirstValue.getvalue()as floatHMagicka = gMagicka + 0.1if pMagicka > gMagicka  Game.GetPlayer().SetActorValue("MagickaRate", 0)  if PMagicka > HMagicka && HMagicka < 1.0   Debug.MessageBox("Condition True")   Game.GetPlayer().DamageActorValue("Magicka", 1)  endifelseif PMagicka < GMagicka  Game.GetPlayer().SetActorValue("MagickaRate", 0.7)endifUpdateMessage.Show( pMagicka, gMagicka, HMagicka )

PMagicka can never go above 1.0 so how in the heck is it somehow returning a true? HMagicka is 1.3 so how can it POSSIBLY be below 1.0??
This has been driving me insane!

edit: The UpdateMessage.show at the end of the code appears to show all of the correct values.
Where is pMagicka and gMagicka? Variables are case sensitive are they not? If so then pMagicka and gMagicka are not PMagicka and GMagicka as you've shown us.
User avatar
louise tagg
 
Posts: 3394
Joined: Sun Aug 06, 2006 8:32 am

Post » Sat Nov 17, 2012 6:46 am

Where is pMagicka and gMagicka? Variables are case sensitive are they not?

They aren't, so it will compile either way. I think the confusion is that the code was changed in response to the questions so now it's not consistent with his text.
User avatar
patricia kris
 
Posts: 3348
Joined: Tue Feb 13, 2007 5:49 am

Post » Sat Nov 17, 2012 5:25 am

The problem is, that with the current code unchanged from the OP no matter what
Debug.MessageBox("Condition True") always fires off even when the condition should not be true. All I need is a condition where its only true when PMagicka is 10% above GMagicka. Attempting to do this has
caused nothing but fail after fail. Everything else seems to work just fine. Its driving me insane as this should not be that complex!
User avatar
Talitha Kukk
 
Posts: 3477
Joined: Sun Oct 08, 2006 1:14 am

Post » Sat Nov 17, 2012 1:31 pm

You would write that condition like:
The problem is, that with the current code unchanged from the OP no matter what
Debug.MessageBox("Condition True") always fires off even when the condition should not be true. All I need is a condition where its only true when PMagicka is 10% above GMagicka.

I had no idea that's what you were trying to accomplish :wink:

Here, try this code:
If PMagicka > (GMagicka * 1.10)  ;You read this as: is PMagicka greater than 110% of GMagicka;PMagicka is 10% above GMagickaElse;do false hereEndIf
User avatar
KiiSsez jdgaf Benzler
 
Posts: 3546
Joined: Fri Mar 16, 2007 7:10 am

Post » Sat Nov 17, 2012 10:41 am

Thanks ill try that, from what I can tell right now the problem seems to be stemming from the global variable. If I replace it with GMagicka = 0.8 or GMagicka = 1.2 ect instead of referencing the global variable everything suddenly works perfectly. That global var is getting messed up.

Ill try what you just said
User avatar
Nathan Maughan
 
Posts: 3405
Joined: Sun Jun 10, 2007 11:24 pm

Post » Sat Nov 17, 2012 7:39 pm

PMagicka > (GMagicka * 1.10) still returns true when PMagicka is not larger than GMagicka... I suspect that I am just not properly referencing the global variable??
User avatar
Jodie Bardgett
 
Posts: 3491
Joined: Sat Jul 29, 2006 9:38 pm

Post » Sat Nov 17, 2012 12:06 pm

PMagicka > (GMagicka * 1.10) still returns true when PMagicka is not larger than GMagicka... I suspect that I am just not properly referencing the global variable??
How about some examples from a trace log so you can easily print what's happening. I see you're using the global.GetValue() and global.SetValue() from your code so I don't know why that should be a problem. I've done this kind of check many times and never had even a small problem, so it's likely something really basic :wink:

Edit:
Here's a small sample of similiar code (obviously not exactly what you need so you can't cuut & paste) but it gives you an idea:
Float currentHealthPercent = Self.GetAVPercentage("health")If Self.IsInCombat() &&  currentHealthPercent < healTriggerPercent

healTriggerPercent is defined at the start as a percent so 0.5 for 50% health, 0.33 for 33% health, etc.

We can get yours to work too!
User avatar
Spencey!
 
Posts: 3221
Joined: Thu Aug 17, 2006 12:18 am

Post » Sat Nov 17, 2012 6:17 pm

Its confirmed, even though I specifically set the global variable to 1.20
ATHSthirstValue.SetValue(1.20)
The second I attempt to getvalue
GMagicka = ATHSthirstValue.getvalue()
It returns something that is always less than PMagicka no matter what... I dont have the full debugging trace thing setup atm but it looks like ill need it to figure out this one... BAH this should have been an easy script :/

I just
( GMagicka = ATHSthirstValue.getvalue() * 100000)
and its still comes out less than PMagicka... Headdesk... AND less than 1.0 too!
IS THIS A FRIGGEN BUG???
User avatar
john page
 
Posts: 3401
Joined: Thu May 31, 2007 10:52 pm

Post » Sat Nov 17, 2012 7:20 am

I think I figured out the problem. I believe that global variables cannot be referenced more than once at a time by a single script. Example RegisterForSingleUpdateGameTime and RegisterForUpdate(1) in the same script might cause conflicts if they both reference the same global variable.

GMagicka randomly becomes 0.0000 without warning or reason over and over again at irregular intervals. I suspect its possible that this is why any statement that uses that global var suddenly acts always true... *Head desk*

Confirmed: it works perfectly now, I wasted so much time on such a silly bug...
User avatar
Leticia Hernandez
 
Posts: 3426
Joined: Tue Oct 23, 2007 9:46 am

Post » Sat Nov 17, 2012 12:41 pm

There is an issue - I think - where if you update the value of a global and in the same script want to get at the new value, you have to run some sort of "process" command.

For the life of me I can't remember the name of it, nor find it in the wiki, though.

(can anyone remember - Or am I just talking nonsense??)
User avatar
Alexx Peace
 
Posts: 3432
Joined: Thu Jul 20, 2006 5:55 pm

Post » Sat Nov 17, 2012 3:33 pm

You may not be able to define a local variable with a global in the same line. I use this kind of stuff a bunch and never have any problems. What I would suggest trying is to define your local variable ("float gMagicka"); then on a different line, set "gMagicka = yourGlob.getValue()". GetValue may also need to be done inside an actual event instead of at the top - that might be what the problem is.

But if you gMag variable is never "filled" correctly, it'll return 0 - no matter how much you multiply it by (though changing that "* 100000" to "+ 100000" I suspect would work).
User avatar
Jhenna lee Lizama
 
Posts: 3344
Joined: Wed Jun 06, 2007 5:39 am

Post » Sat Nov 17, 2012 7:08 am

If it was me, I'd stick else clauses on each of those if statements, and then I'd stick traces inside each branch so I knew for sure what was happening. And I'd print the variables being tested in each trace as well.

I notice you don't have a case to handle pMagicka == gMagicka. Is that intentional?
User avatar
Sebrina Johnstone
 
Posts: 3456
Joined: Sat Jun 24, 2006 12:58 pm

Post » Sat Nov 17, 2012 11:50 am

There is an issue - I think - where if you update the value of a global and in the same script want to get at the new value, you have to run some sort of "process" command.

For the life of me I can't remember the name of it, nor find it in the wiki, though.

(can anyone remember - Or am I just talking nonsense??)

Are you thinking: http://www.creationkit.com/UpdateCurrentInstanceGlobal_-_Quest?
User avatar
W E I R D
 
Posts: 3496
Joined: Tue Mar 20, 2007 10:08 am

Post » Sat Nov 17, 2012 4:10 am

Are you thinking: http://www.creationkit.com/UpdateCurrentInstanceGlobal_-_Quest?
Yes I am ... thank the lord for that!! :)
User avatar
Chloe Botham
 
Posts: 3537
Joined: Wed Aug 30, 2006 12:11 am

Post » Sat Nov 17, 2012 3:31 pm

updatecurrentinstanceglobal is only used for updating the global's printed text value to reflect its real-time value (i.e. "Collected 5/5 fire salts for Some Dude" when collecting the 5th fire salt - otherwise it would read 4/5 fire salts even though the global's value is 5)

the issue with the global reading a value of 0 all the time sounds more like a problem in the update block. RegisterForSingleUpdateGameTime and RegisterForSingleUpdate should not interfere with one another and i dont see any reason why it would revert the global's value back to 0 on its own. Update events always read the values in true real time.
User avatar
FoReVeR_Me_N
 
Posts: 3556
Joined: Wed Sep 05, 2007 8:25 pm

Post » Sat Nov 17, 2012 6:06 pm

Ultimately the problem was solved by simply breaking the script into two smaller scripts each with its own register for update block. One script now handles periodic updates and the other handles real time updates.
User avatar
Darlene Delk
 
Posts: 3413
Joined: Mon Aug 27, 2007 3:48 am

Post » Sat Nov 17, 2012 4:41 am

Congrats! Glad you got it working.
User avatar
Harry Leon
 
Posts: 3381
Joined: Tue Jun 12, 2007 3:53 am

Post » Sat Nov 17, 2012 3:42 pm

Congrats! Glad you got it working.

Thank you for helping :)
User avatar
IM NOT EASY
 
Posts: 3419
Joined: Mon Aug 13, 2007 10:48 pm


Return to V - Skyrim