| 06-03-2007, 06:30 AM | #1 |
I'm having a really wierd bug with a null string. Ill post the code first then fill you all in. JASS:private function UnitToChat takes nothing returns nothing local unit u = NPCunit[toNPC] local real x1 = GetUnitX(u) local real y1 = GetUnitY(u) local real x2 = GetUnitX(heroUnit) local real y2 = GetUnitY(heroUnit) local string key = KEY_NPC+I2S(toNPC) local integer chat = GetStoredInteger(ESE_cache, key, KEY_NPC_WANT_CHAT) if toNPC!=0 then if SquareRoot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) <= NPC_TALK_DISTANCE then if chat!=0 then call displayChat(chat, GetStoredString(ESE_cache, key, KEY_NPC_NAME)) call DestroyEffect(NPCeffect[toNPC]) call FlushStoredInteger(ESE_cache, key, KEY_NPC_WANT_CHAT) else call displayChat(GetStoredInteger(ESE_cache, key, KEY_NPC_CHAT), GetStoredString(ESE_cache, key, KEY_NPC_NAME)) endif call SetUnitFacing(u, bj_RADTODEG*Atan2(y2-y1, x2-x1)) call BJDebugMsg(NPCcam[toNPC]) if NPCcam[toNPC] != "" then call BJDebugMsg("Code Exists!") set tempNPC = u call ExecuteFunc(NPCcam[toNPC]) endif set toNPC = 0 call IssueImmediateOrder(heroUnit, "stop") call SetUnitFacing(heroUnit, bj_RADTODEG*Atan2(y1-y2, x1-x2)) call PauseUnit(heroUnit, true) else call IssuePointOrder(heroUnit, "move", x1, y1) call TimerStart(NPC_Timer, NPC_PERIOD, false, function UnitToChat) endif endif set u = null endfunction private function npcOrdered takes nothing returns nothing local unit u = GetTriggerUnit() local integer i = GetUnitUserData(u) local real x1 = GetUnitX(u) local real y1 = GetUnitY(u) local real x2 = GetUnitX(heroUnit) local real y2 = GetUnitY(heroUnit) local string key = KEY_NPC+I2S(i) local integer chat = GetStoredInteger(ESE_cache, key, KEY_NPC_WANT_CHAT) if i!=0 and not chatVisible then if SquareRoot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) <= NPC_TALK_DISTANCE then set questVisible = false if chat!=0 then call displayChat(chat, GetStoredString(ESE_cache, key, KEY_NPC_NAME)) call DestroyEffect(NPCeffect[i]) call FlushStoredInteger(ESE_cache, key, KEY_NPC_WANT_CHAT) else call displayChat(GetStoredInteger(ESE_cache, key, KEY_NPC_CHAT), GetStoredString(ESE_cache, key, KEY_NPC_NAME)) endif call SetUnitFacing(u, bj_RADTODEG*Atan2(y2-y1, x2-x1)) call SetUnitFacing(heroUnit, bj_RADTODEG*Atan2(y1-y2, x1-x2)) call BJDebugMsg(NPCcam[toNPC]) if NPCcam[toNPC] != "" then call BJDebugMsg("Code Exists!") set tempNPC = u call ExecuteFunc(NPCcam[toNPC]) endif call PauseUnit(heroUnit, true) else set toNPC = i call IssuePointOrder(heroUnit, "move", x1, y1) call TimerStart(NPC_Timer, NPC_PERIOD, false, function UnitToChat) endif endif set u = null endfunction The first function works fine, and is used within a loop to check when the unit does come within range of the NPC unit. The second function fires through a selection event trigger. Both work fine except for the highlighted parts. The cream highlight is the problem-ed if/then/else check. For some reason, even if the string is null, it will still run. It is the same lines of code, copied directly from the first function. Now, the problem is that if the string is null and it passes the check, it will try to run a function of name null. This crashes the game. I've tried re-copying the problem-ed lines of code multiple times, and still no luck. Help? |
| 06-20-2007, 03:35 AM | #2 |
Well, all I know is that I've had a few instances where if then's bug out, and sometimes it is best to use an "==true". I have no idea why though. -.-* |
| 06-20-2007, 04:44 AM | #3 |
oh noh no more ==true non-sense that's totally unrelated to this. And it is perfectly safe not to use ==true inside if conditions. . There are 2 "null strings" , one is null and "" |
| 06-20-2007, 06:06 AM | #4 |
I don't have to worry about a null string, since the string is never used unless it is set to "" or some other value. The issue was that both functions used the same method to check, yet they yielded different results. This really doesn't matter anymore because I think I found a way around it. I've also taking some time off of modding to study for finals. |
