Jump to content

attempt to index field '?' (a userdata value)


'LinKin

Recommended Posts

Hello,

I've a small trouble.

local listMaps = exports.mapmanager:getMapsCompatibleWithGamemode(exports.mapmanager:getRunningGamemode() )

This is a complete list of the maps, in my case the gamemode is 'Race'.

I created a table, and in it, I will insert some maps; Like this:

local myTable = { }

for i, map in ipairs (listMaps) do

if getResourceInfo(map, "name") == mapName(*) then

// custom code...Puts the map in myTable.

end

end

So far works good.

But when I want to remove a map from my custom table, I use the following:

if getResourceInfo(myTable[1][1], "name") == mapSelected(*) then

// custom code

end

But the in-game debugger tells me this error:

ERROR: myscript\server.lua:145: attempt to index field '?' (a userdata value)

The line 145 is if getResourceInfo(myTable[1][1], "name") == mapSelected then

______________________________________________________________________________________________________________

(*): mapName & mapSelected are strings that I give (i.e [DD] Cross)

Link to comment

Solved.

I was treating 'myTable' as a vector, not a matrice. So by the time it was making this condition;

if getResourceInfo(myTable[1][1], "name") == mapSelected then

It was trying to access a position that did not exist. As a vector, when trying to access a position you gotta do it like this;

myTable[index]

That's why the error was similar to what Java says when you try accessing to a non-existing position;

ERROR: myscript\server.lua:145: attempt to index field '?' (a userdata value)

Thank you guys for the interest.

- Little mistakes that we commit

Link to comment
Userdata is elements iirc. It may be other things too.
Lua provides a basic type specifically for this: userdata. A userdatum offers a raw memory area with no predefined operations in Lua.

I've experienced userdata when outputting an array, an element, some weird variables. It's just about everything miscellaneous as far as I can see. And like it says ".. with no predefined operations..", so it's pretty much like that.

But yeah, glad you got it fixed.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...