Jump to content

Lua or C++ issue? Attempt to index a global 'variable' ( Nil value )


Recommended Posts

Hi!

Beforehand, thanks for coming by! 😁

My main issue currently is a nil value. I know, if it's empty, just initialize it or give him some value. But i'm completly lost tbh...

 

Let me elaborate a little bit:

I have tried to create a copy of the pet system (the old one, not the new). By doing basically a copy of the existed code and changing the names of the same (PetSystem.cpp -> HorseSystem.cpp | class CPetSystem -> class cHorseSystem and etc etc )

I have searched everywhere in the code, where is initialized, where is destroyed, where is used (pet system) and did the same for the copied one.

Everything seemed fine, went well regarding the compilation and the rest. (I was truly happy to test it, like a kid.. just a childish thing tho)

But when trying to call a simple function from LUA, like: horsesystem.is_summon. It just throws an error: Attempt to index a global 'horsesystem' ( Nil value )

Like in the example below: 

Spoiler

spacer.png

The line that throws the null pointer:

Spoiler

spacer.png

 

I have already checked everything ( I think, might be missing something tho ), my AddLuaFunctionTable is complete (with the funcs) and everything else. But still the same exception...

I even did a comparation by adding in a quest:

Spoiler

horsesystem.is_summon(Etc etc)

pet.is_summon(Etc etc)

 

 (The Etc is just an example of a parameter for this scenario)

 

The pet line returns a value. The horsesystem just throws an exception

My mental war is:

Is the CHorseSystem even initialized ? (I copied everything from the PetSystem, soo.. it should be)

I created as well a new function in AddLuaFunctionTable called test (from LUA side -> horsesystem.test(2022)) and it should be returning just an int like 2022 (not even calling anything from HorseSystem.cpp, just returning automatically from questlua_horsesystem.cpp). But it still gives me an exception.

That's why I'm kinda confused if I need to search more in the LUA side or trying to fix where is in the source.

Already searched everywhere about this issue,  most of the topics are just saying to check in questlib and etc. But for what I understood, that's not my case.

Already spent a lot of time by myself, and I don't mind actually, because it is fun (a lot) when you find the cause and you fix it. But in this case.. I'm having a mental breakdown.

Might be an easy thing to fix, but I'm completly destroyed 😅

 

Thank you in advance!

Any help is precious! Even for discussing. I might get a clue regarding the issue 😁

 

Kind regards

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

Hi @ Speachless!

Thanks for the message and I hope you're doing well.

Regarding your anwser:

3 hours ago, Speachless said:

In server src you must have a questlua_name.cpp with that name registered, example:

CQuestManager::instance().AddLuaFunctionTable("newpet", newpet_functions);

 

 I have it already. Named of questlua_horsesystem.cpp and my AddLuaFunctionTable contains the name and the respective list as shown below:

Spoiler

spacer.png

The methods seems fine as well, mostly are from the pet system ( the is_summon for example ). I even created a simple method to return 2022, Like I said previously, just to check if horsesystem was being called:

Spoiler

CrxxO82.png

but no successful result at all. The "persistent" exception (damn you attempt to index global 'variable' 😬) happens in LUA.

 

Once again, thanks for the reply!

kind regards!

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

7 minutes ago, Speachless said:

Maybe it's because you added that questflag directly to it. Try with something like

local mobVnum = ADD_VNUM_HERE
if true == horsesystem.is_summon(mobVnum) then 

and the vnum to be different than 0

The same exception happens, by creating a variable with the mob ID or adding directly to the method.

Attempt to index a global 'horsesystem' ( Nil value )

 

Kind regards!

Link to comment
Share on other sites

Hi @ PACI

Thank u for your answer and I hope this message finds you well!

Regarding your warning:

34 minutes ago, PACI said:

 

Make sure you call this function on CQuestManager::InitializeLua() - otherwise it won't register it.

It's there: RegisterHorseSystemTable() ( something like that ) and declared on .H file as external method ( since his implementation is in HorseSystem.cpp )

I did a copy from the PetSystem. That's why it's so weird. It should have the same behaviour but that's not the case.

 

Once again, thank you for your reply!

Kind regards

Edited by Veysel
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.