abi>>forums (http://www.anythingbutipod.com/forum/index.php)
-   Zen X-Fi2 Applications & Development (http://www.anythingbutipod.com/forum/forumdisplay.php?f=221)
-   -   Table assigning-Bug (http://www.anythingbutipod.com/forum/showthread.php?t=67050)

jbob182 12-14-2011 09:58 PM

Table assigning-Bug
After many tries to fix a bug I have encountered, and much research, I am no closer to solving this bug then when I started. So I was wondering if anyone had any ideas on how to fix it.

In Pingus, we use two tables, to map our the penguins actions ( one for left movement, and one for right movement). What we do is, compute the penguin's action at a certian pixel ( falling, moving, climbing a hill, turning, ect) and save that result to a table with a indices of the x and y coordinate ( we have tried several ways to write the indices, ranging from strings to numbers). Then if a penguin reaches a coordinates that has already been encountered, we just grab the end result from the table.

The problem starts when we attempt to use abilities such as the digger or miner(we have also re-routed the ability's code to use the walker's code which has not crashed yet, but it still crashes). If we try to assign a value to a table (ie: record_table[tostring(p.x) .. "_xpos" .. tostring(p.y) .. "_ypos"] = "falling") or reading from the table (ie: if record_table[corrdiante_string] == nil) then the player will crash, with the error: "attempt to call a nil value". The game also doesnt crash for every coordinate, so the digger will work for a random amount of time, then that error occurs.

here is a basic sample of the code we use:

function memoize_collision_right(x,y,p,ability_effect_value)
    local new_value = tostring(x) .. "00" .. tostring(y)
    new_value = tonumber(new_value)
    if memoize_collision_right_dat[new_value] == nil and p.state ~= "climbing" and p.type ~= "builder" then
        if ability_effect_value ~= nil then
    elseif p.state == "climbing" then
    return memoize_collision_right_dat[new_value]

Note: our first try was to use table.insert instead of just writing memoize_collision_right_dat[new_value] = "falling" , but that did not help either. And this bug does not exist on the simulator.

Does anyone have a solution or know why this would happen, our entire project hangs on this bug.


Jbob & Redwolfhome

Kalle Kula 12-15-2011 05:34 AM

Maybe you can rewrite the function for debugging purpose by replace the and's with full-cached if's to check that there are no uncached state. If you use elseif also do a last else. Even if you think there are states that newer could be reached maybe there is, use simple print("bug.....") for that states. Also check for nil or empty on strings.

jbob182 12-15-2011 07:39 AM

The hardest part about this though, is that it only occurs on the Player, so I will just write those variables to a text file.

Kalle Kula 12-15-2011 11:13 AM

If it's only happens on the player, when I guess the trouble is somewhere else in your code. Maybe there you set the p.state. The only reason for "the only player bug thing" I can think out right now, is some dependency on os.time() or os.clock()

jbob182 12-15-2011 05:39 PM

It is in fact editing the table, because if I were to use the original setup ( just assign the table with the line: table[index] = "falling" ) it would crash, and if i removed it, it would not crash. Our engine would not be disrupted with os.time or os.sleep because we have coded our program in such a way, that we just call engine.time() and it will return the same format on the player and adk.

Furthermore, there are no nil values when it crashes, I have outputed every value it uses besides the table, and they all produce good values.

jbob182 12-18-2011 11:50 AM

After days of theorizing, I have found the issue! There is an maximum table index limit. This limit is 1024 (you can not have anyone more then 1024 entries into a table). Which is very surprising; our penguins are 32x32 AND if you multiply 32 by 32, you get 1024!

Kalle Kula 12-18-2011 03:08 PM

If I understand you right, there is a 1024 limit on the table indexies. Isn't what a limit on number index by 2^(1024 *8), and that's a big one, Well then mybee I can suggest some kind of remapping.

jbob182 12-18-2011 03:10 PM

I do not follow you, could you re-word it? I have just made a tile-table setup, but it causes a sever ram overload with not even 1/8 of the tables made :( even if i remove sound and plenty of pictures, it still overloads. After some calculations, the only way to support levels, is to push everything outside of ram, and only have the bare necessitates run in ram, and swap space for memory to handle everything else.

Kalle Kula 12-18-2011 03:41 PM

maybe I missunderstand you but you want to do something like
sometable = { }
sometable["here goes some 1024 character it's about a A4 paper size or more.."]

jbob182 12-18-2011 03:59 PM

Nope, it is more like this:

sometable[1022] = "falling" --- No crash!
sometable[1024] = "falling" --- crash!

It doesnt matter if it is numbers or strings for indicies

Kalle Kula 01-02-2012 08:22 AM

This had been laying for some time and maybe you already solved it. Anyway I think user Jan_DK already have investigated the limit of the player max tablesize.

we get 32768*4-128K usable bytes out of a
single dim array
in http://www.anythingbutipod.com/forum...t=50811&page=2
And that's far beyone sometable[1024]
looking at your function igain I see that you do:

local new_value = tostring(x) .. "00" .. tostring(y)
new_value = tonumber(new_value)
and if I get it right, x and y has max of 32, and new_value gets a max of 320032.
memoize_collision_right_dat[320032] ?!

maybe you wanted:
local new_value = string.format("%2d%02d", x,y)

jbob182 01-02-2012 10:44 AM


local new_value = tostring(x) .. "00" .. tostring(y)
new_value = tonumber(new_value)
and if I get it right, x and y has max of 32, and new_value gets a max of 320032.
memoize_collision_right_dat[320032] ?!

maybe you wanted:
local new_value = string.format("%2d%02d", x,y)

We did manage to fix it by using sub tables, ie: tablefoo[1019][1019]

As for your suggestion, we have tried basically every format possible for the indicies, ie: numbers, strings like 33_xpos44_ypos.

x and y does not have a max of 32 either, they are the penguins position on the map, so x and y can be any number.

All times are GMT -5. The time now is 11:24 PM.