Page 1 of 1

[FIXED]LUA looping error

Posted: Fri Aug 02, 2013 9:24 pm
by John Adams
Here's an unlikely scenario for regular users, but we probably should fix it for Devs.

I dropped a breakpoint in my new Interrupt() LUA function and was stepping through the code to see what was wrong. My client disconnected of course, but World started to flip out behind me. Even after my character completely lost connection.
CastSpellError.jpg

Re: LUA looping error

Posted: Fri Aug 02, 2013 9:35 pm
by John Adams
Ahh, this is not about my breakpoint... i think it's the script I'm trying. Edited, it looks like this:

Code: Select all

    function spawn(NPC)
       SetLuaBrain(NPC)
       SetBrainTick(NPC, 500)
    end

    function respawn(NPC)
        spawn(NPC)
    end

    function Think(NPC)
       if GetTarget(NPC) ~= nil then
          CastSpell(GetTarget(NPC), 30000, 4, NPC)
       end
    end
Edit: And, once again comes down to user error because I have no idea how anything works anymore :p I put this script on my foe, and there are 50 of them spawned in the area and none of them were mad at me at the time ;)

Maybe this exposed a bug in the Brain? Not that anyone would ever use the Brain int his manner but us.

Re: LUA looping error

Posted: Fri Aug 02, 2013 9:54 pm
by Jabantiz
The "if GetTarget(NPC) ~= nil then" should probably be in another if to check to see in the npc is in combat. However that if should prevent CastSpell from being called with no target.

Out of curiosity could you try the following when you get a chance

Code: Select all

function Think(NPC)
    target = GetTarget(NPC)
    if target ~= nil then
        CastSpell(target, 30000, 4, NPC)
    end
end

Re: LUA looping error

Posted: Fri Aug 02, 2013 10:11 pm
by John Adams
Same thing, Jab.

Re: LUA looping error

Posted: Fri Aug 02, 2013 10:24 pm
by Jabantiz
Odd, have to ask but are you sure on the spell id? No clue why the target it is getting past the if but failing in the CastSpell function... will have to look into this tomorrow if I can get enough free time.

Re: LUA looping error

Posted: Fri Aug 02, 2013 11:31 pm
by John Adams
Yup, definitely 30,000. It is the first spell of a Guardian (class_id * 10,000). Tier 4 info is in place all the way down the line. I can cast the same spell on the NPC, and when using it as a spawn_npc_spell list, they can cast it on me.

It's also the only spell in my local database, so it's kinda hard even for me to mess that one up :)

Re: LUA looping error

Posted: Sat Aug 03, 2013 11:56 am
by Jabantiz
I figured it was right just had to ask to make sure as the error says target or spell id. I am going to rewrite the function locally to the style I have been doing my recent functions to provided better error messages to try and pinpoint the problem, do you want me to put the changes on svn as well?

Re: LUA looping error

Posted: Sat Aug 03, 2013 1:11 pm
by John Adams
Might as well. Anything to avoid loopy red text in the console. I don't want to scare anyone :)

Re: LUA looping error

Posted: Sat Aug 03, 2013 1:19 pm
by Jabantiz
still get the error message they are just more specific then target or spell id is not valid.

Rewrote it already on my end and this is where the CastSpell lua function is failing

Code: Select all

if (!target) {
		lua_interface->LogError("LUA CastSpell command error: target is not a valid spawn");
		return 0;
	}
I am at a loss now because if target is null then in the lua script it should never get past this if

Code: Select all

if GetTarget(NPC) ~= nil then
even tried putting the target into its own variable and checking that but I get the same results, it gets past the if in the lua but fails in the c++ code...

Re: LUA looping error

Posted: Sat Aug 03, 2013 2:13 pm
by Jabantiz
Ok figured it out, was a bug with GetTarget() lua function. I think I would just confuse people explaining the details so I will just say that it was always returning a valid pointer to lua even if the spawn didn't have a target.

Committed the fix for it.

Also want to point out that lua brain we were testing with won't actually do anything as the spawns target gets set in the AI and we are overriding it with that script and never setting a target ourself.

Re: LUA looping error

Posted: Sat Aug 03, 2013 2:18 pm
by thefoof
Jabantiz wrote:Also want to point out that lua brain we were testing with won't actually do anything as the spawns target gets set in the AI and we are overriding it with that script and never setting a target ourself.
Ah that's interesting, didn't know the brain was on that deep of a level