Aller au contenu

Photo

help! "If condition don't run"


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
el.sombrero

el.sombrero
  • Members
  • 100 messages
 Hey guys,

 I´ve installed a cronometer at my projetc. After a time I discovered it had a bug... now and again I would get negative seconds for result.. I thought about it a littel and figured out that it was because seconds marker at the clock restarts every full circle ( 60 seconds). So, If my first marker was 02:45 and my second one was 4:15 I would get  02: -30 for result ( 4 minutes - 2 minutes = 2 minutes; 15 seconds - 45 seconds= -30 seconds).
 The solution I got for this problem was to put a "If" condition that  says "if seconds are less than or equal to -1, add 60 to seconds and subtract 1 from minutes". The thing is, it seems that my condition simply isnt been triggered, I still get the same problems... any one here can help me out?  Bellow goes that part of my code (it compiles ok), I will not post the whole script because it is 650 lines long.

int nMinV1LA1 = GetLocalInt(oPC, "nMinutes_V1LA1") - GetLocalInt(oPC, "initial_minute");int nSecV1LA1 = GetLocalInt(oPC, "nSeconds_V1LA1") - GetLocalInt(oPC, "initial_second"); //Correct the problem that occurs when seconds at SecV1LA1 are less than at "initial_second"  if (GetLocalInt(oPC, "nSecV1LA1") < 0)  {       nSecV1LA1 += 60;
  nMinV1LA1 -= 1;
  }

#2
kevL

kevL
  • Members
  • 4 078 messages
It sounds like the local int's on the PC won't ever be less than zero. Try using nSecV1LA1 directly,

if (nSecV1LA1 < 0)
{
	nSecV1LA1 += 60;
	nMinV1LA1 -= 1;
}


#3
Dann-J

Dann-J
  • Members
  • 3 161 messages
Wouldn't it be easier to do all the calculations in seconds, then convert to minutes:seconds when necessary?

#4
el.sombrero

el.sombrero
  • Members
  • 100 messages
The problem is I'm using the neverwinternights 2 clock, and it only gives me time in numbers and seconds... I would first have to convert all to seconds, then calculate, then convert again... to much trouble

#5
el.sombrero

el.sombrero
  • Members
  • 100 messages
Hey KevL,
It solved my problem... but I dont understand the difference between the previous condition and the one you proposed... can you explain it to me, so I dont do the same mistake again?
thx!

#6
kevL

kevL
  • Members
  • 4 078 messages
well in your first version:

if (GetLocalInt(oPC, "nSecV1LA1") < 0)

it's trying to get a local_int from the PC-object that ( i guess ) doesn't actually exist. Rather, the local_int on the PC is, as stated:

GetLocalInt(oPC, "nSeconds_V1LA1")

So i'm thinking you got confused between the local_int on the PC and the variable_int ( nSecV1LA1 ) that flows through the code, in the script itself

ie. you don't have to 'get' nSecV1LA1 since it's being calculated on-the-fly,

#7
el.sombrero

el.sombrero
  • Members
  • 100 messages
thx again man!

#8
kevL

kevL
  • Members
  • 4 078 messages
np