Jump to content

Function arrays not working on iphone


Xira

Recommended Posts

I'm creating a Wherigo using Urwigo.

One of the structures I'm using is an array of 10 functions. It works fine in the emulator, on webwigo, and WhereYouGo on Android. It doesn't work on apple devices. 

The test Lua code is provided below and I've attached output screenshots. In the code, vProgress is a Urwigo variable initialized to "xxxxxxxxxx".

What seems to be happening is that, on an Apple device, the only entry in the function array that can be accessed is the first one. What the player sees are 9 Lua Alerts that say "Don't know how to call '<null>'".

I've tested a simpler array using the same constants. The entries in that array can be accessed just fine so is it a problem with having functions as array entries?

Can anyone give me any insight into why this is happening?

Thank you.

======================================

cBench = 4
cBlocks = 7
cCavity = 3
cSquirrels = 2
cGap = 9
cReturn = 1
cRoot = 5
cRoad = 10
cWart = 6
cWeird = 8

CR = [[
]]

function DoTest()
    -- this works on emulator, webwigo, and android. it does not work on iphone
    GetX = {
    [cBench] = function() return tonumber(string.sub(tostring(Player.ObjectLocation.latitude),6,6)) end,
    [cBlocks] = function() return tonumber(string.sub(tostring(Player.ObjectLocation.longitude),6,6)) end,
    [cCavity] = function() return tonumber(string.sub(tostring(Player.ObjectLocation.longitude),7,7))    end,
    [cSquirrels] = function() return tonumber(string.sub(tostring(Player.ObjectLocation.latitude),5,5)) end,
    [cGap] = function() return tonumber(string.sub(tostring(Player.ObjectLocation.latitude),4,4)) end,
    [cReturn] = function() return tonumber(string.sub(tostring(Player.ObjectLocation.latitude),4,4)) end,
    [cRoot] = function() return tonumber(string.sub(tostring(Player.ObjectLocation.longitude),7,7)) end,
    [cRoad] = function() return tonumber(string.sub(tostring(Player.ObjectLocation.longitude),2,2)) end,
    [cWart] = function() return tonumber(string.sub(tostring(Player.ObjectLocation.longitude),5,5)) end,
    [cWeird] = function() return tonumber(string.sub(tostring(Player.ObjectLocation.longitude),7,7)) end
    }
    
    debugstr=""
    for i = 1,10 do
        debugstr = debugstr.."i"..i.." "
        x = GetX()
        debugstr = debugstr .. x.. " "
        newStr = string.sub(vProgress,1,i-1)..x..string.sub(vProgress,i+1)
        vProgress = newStr
    end
    
    -- a check to see if the constants actually have the values I expect them to have
    local Cstring = cBench.." "..cBlocks.." "..cCavity.." ".. cSquirrels.." ".. cGap.." ".. cReturn.." ".. cRoot.." ".. cRoad.." ".. cWart.." ".. cWeird    
    local outputstr = "The constants: "..Cstring..CR..CR
    outputstr = outputstr.."debugstr: "..debugstr..CR..CR
    outputstr = outputstr.."vProgress: "..vProgress
    Wherigo.MessageBox{Text = outputstr}
end

Ipad screenshot.jpg

Emulator output.jpg

  • Upvote 1
Link to comment

I have this problem as well in a cartridge and couldn't figure out why it was happening, because I don't own an iPhone...
If it turns out this is the reason, thank you for describing the problem! I'll try using a local variable like

for i = 1,10 do
local f = GetX[i]
f()
end

and see if that helps!

-------

Well, unfortunately my changes didn't only not fix it, but apparently caused an infinite loop with the

Quote

Don't know how to call '<null>'

messages... I'm confused...

Edited by JakeDot
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...