pcall error

Hello all I have this error and I narrowed it down to a small peice of code but for the life of me I cant figure out what is wrong.

This is the error:
Lua Runtime Error: lua_pcall failed with status: 2, error message is: ?:0: attempt to perform arithmetic on upvalue ‘?’ (a string value)

here is the code I have been using.

local now = os.time()  
 local footballlastPurchasetime = tonumber (footballlastPurchase)  
 print("now time")  
 if (now \> (footballlastPurchase + 1800)) then  
 -- 1800 is 30 minutes need to change to 604900 = 7 days  
 saveValue( "football.data",footballlock )  
 saveValue( footballFilename, tostring(footballlock) )  
 --reset the footbal data to 0  
 storyboard.gotoScene( "maingame", "crossFade", 500 )  
 end  
  

Thanks for the help in advanced.
[import]uid: 34105 topic_id: 35429 reply_id: 335429[/import]

? in this case means it can’t figure out how to handle a variable.

  1. Is footballlastPurchaseTime declared previously? Because in that code, your line 2 is basically saying

x = tonumber(x) which can’t evaluate since it doesn’t know what the variable is. (It would work, though, if (a) this is actually a function and (b) that variable was previously declared OUTSIDE of the function.

  1. Specifically the code is saying that the variable is a string even though you used tonumber(), so it’s really important to see what that value is…
    [import]uid: 41884 topic_id: 35429 reply_id: 140761[/import]

Thanks for your reply. This is what I have declared at the top.

local footballlock = 0  
local footballlastPurchase = "footballlastpurchase.data"   
local footballlastPurchasetime = tonumber (footballlastPurchase)  
local footballFilename = "football.data"  

Here is the code again I realized i forgot part of the code name.

local now = os.time()  
 local footballlastPurchasetime = tonumber (footballlastPurchase)  
 print("now time")  
 if (now \> (footballlastPurchasetime + 1800)) then  
 -- 1800 is 30 minutes need to change to 604900 = 7 days  
 saveValue( "football.data",footballlock )  
 saveValue( footballFilename, tostring(footballlock) )  
 --reset the footbal data to 0  
 storyboard.gotoScene( "maingame", "crossFade", 500 )  
 end  

Hopefully this clarifies the variable.

[import]uid: 34105 topic_id: 35429 reply_id: 140762[/import]

snowboard, no replies so I’ll jump in over my head, I’d think Richard will be back, but here’s my take.

This doesn’t make sense to me…

local footballlastPurchase = “footballlastpurchase.data”
local footballlastPurchasetime = tonumber (footballlastpurchase)

I don’t see how the string “footballlastpurchase.data” every gets converted to a number, it’s a string of text and don’t think it can ever be converted to a number that can be added to 1800 or compared to the time.

I can see if you had data in a table called footballlastpurchase and it has a number value stored as .data, then you could retrieve it like this…no string " " though and there would be no need for a tonumber call.

footballlastpurchase.data = 1200
local footballlastPurchase = footballlastpurchase.data

or if footballlastpurchase.data = “1200” then use the tonumber call
local footballlastPurchase = tonumber(footballlastpurchase.data)

Another thing I don’t understand in your code is your saveValue() that you use a twice.

I’m almost guessing that you are trying to use GGData or Ice to store your values and not doing it correctly, but of course I could be way off base, but without seeing the saveValue() that you are passing params to, everything is just guess work.

I think you’ve got to post your saveValue() for anyone to help further.

I’m a newb, so this is probably the reason I can’t understand how you code could every work, hopefully Richard can clarify.

Hope this help,

Nail

[import]uid: 106779 topic_id: 35429 reply_id: 140870[/import]

Yeah, unfortunately variables are just references; you can’t convert the string “dude” into the variable “dude”; they’re just not the same thing and you would need some sort of “tovariable()” function (which is not a standard lua component, if it even exists.)

The closest format to that I can think of is to use table references.

[code]-- Make a table
local myTable = {}
myTable.importantNumber = 2139

– Reference the table index
local purchasingIndex = “importantNumber”
print(myTable[purchasingIndex]) – 2139[/code]

This works because the variable is a string, and table indices can be strings… [import]uid: 41884 topic_id: 35429 reply_id: 140899[/import]

Thanks very much guys. I figured it out from your input. The problem was I was not loading the data from the data file. So after changing it around this is what i came up with and it worked.

  
local footballlock = 0  
local footballlastPurchase = loadValue ("footballlastpurchase.data")  
local footballData = loadValue ("football.data" )  
local footballbuy = tonumber (footballData)  
local footballcheck = function( event )  
 print("football check")  
 if footballbuy == 1 then  
 print("football buy")  
 local now = os.time()  
 print( "Value = " .. tonumber( now ) )  
 print( "Value2 = " .. tonumber( footballlastPurchase ) )  
 print("now time")  
 if (now \> (footballlastPurchase + 1800)) then  
 -- 1800 is 30 minutes need to change to 604900 = 7 days  
 saveValue( "football.data",footballlock )  
 --reset the footbal data to 0  
 storyboard.gotoScene( "maingame", "crossFade", 500 )  
 end  
 end  
end   
 timer.performWithDelay(200, footballcheck, 1)  
  

Thanks Again

Alberto [import]uid: 34105 topic_id: 35429 reply_id: 140923[/import]

? in this case means it can’t figure out how to handle a variable.

  1. Is footballlastPurchaseTime declared previously? Because in that code, your line 2 is basically saying

x = tonumber(x) which can’t evaluate since it doesn’t know what the variable is. (It would work, though, if (a) this is actually a function and (b) that variable was previously declared OUTSIDE of the function.

  1. Specifically the code is saying that the variable is a string even though you used tonumber(), so it’s really important to see what that value is…
    [import]uid: 41884 topic_id: 35429 reply_id: 140761[/import]

Thanks for your reply. This is what I have declared at the top.

local footballlock = 0  
local footballlastPurchase = "footballlastpurchase.data"   
local footballlastPurchasetime = tonumber (footballlastPurchase)  
local footballFilename = "football.data"  

Here is the code again I realized i forgot part of the code name.

local now = os.time()  
 local footballlastPurchasetime = tonumber (footballlastPurchase)  
 print("now time")  
 if (now \> (footballlastPurchasetime + 1800)) then  
 -- 1800 is 30 minutes need to change to 604900 = 7 days  
 saveValue( "football.data",footballlock )  
 saveValue( footballFilename, tostring(footballlock) )  
 --reset the footbal data to 0  
 storyboard.gotoScene( "maingame", "crossFade", 500 )  
 end  

Hopefully this clarifies the variable.

[import]uid: 34105 topic_id: 35429 reply_id: 140762[/import]

snowboard, no replies so I’ll jump in over my head, I’d think Richard will be back, but here’s my take.

This doesn’t make sense to me…

local footballlastPurchase = “footballlastpurchase.data”
local footballlastPurchasetime = tonumber (footballlastpurchase)

I don’t see how the string “footballlastpurchase.data” every gets converted to a number, it’s a string of text and don’t think it can ever be converted to a number that can be added to 1800 or compared to the time.

I can see if you had data in a table called footballlastpurchase and it has a number value stored as .data, then you could retrieve it like this…no string " " though and there would be no need for a tonumber call.

footballlastpurchase.data = 1200
local footballlastPurchase = footballlastpurchase.data

or if footballlastpurchase.data = “1200” then use the tonumber call
local footballlastPurchase = tonumber(footballlastpurchase.data)

Another thing I don’t understand in your code is your saveValue() that you use a twice.

I’m almost guessing that you are trying to use GGData or Ice to store your values and not doing it correctly, but of course I could be way off base, but without seeing the saveValue() that you are passing params to, everything is just guess work.

I think you’ve got to post your saveValue() for anyone to help further.

I’m a newb, so this is probably the reason I can’t understand how you code could every work, hopefully Richard can clarify.

Hope this help,

Nail

[import]uid: 106779 topic_id: 35429 reply_id: 140870[/import]

Yeah, unfortunately variables are just references; you can’t convert the string “dude” into the variable “dude”; they’re just not the same thing and you would need some sort of “tovariable()” function (which is not a standard lua component, if it even exists.)

The closest format to that I can think of is to use table references.

[code]-- Make a table
local myTable = {}
myTable.importantNumber = 2139

– Reference the table index
local purchasingIndex = “importantNumber”
print(myTable[purchasingIndex]) – 2139[/code]

This works because the variable is a string, and table indices can be strings… [import]uid: 41884 topic_id: 35429 reply_id: 140899[/import]

Thanks very much guys. I figured it out from your input. The problem was I was not loading the data from the data file. So after changing it around this is what i came up with and it worked.

  
local footballlock = 0  
local footballlastPurchase = loadValue ("footballlastpurchase.data")  
local footballData = loadValue ("football.data" )  
local footballbuy = tonumber (footballData)  
local footballcheck = function( event )  
 print("football check")  
 if footballbuy == 1 then  
 print("football buy")  
 local now = os.time()  
 print( "Value = " .. tonumber( now ) )  
 print( "Value2 = " .. tonumber( footballlastPurchase ) )  
 print("now time")  
 if (now \> (footballlastPurchase + 1800)) then  
 -- 1800 is 30 minutes need to change to 604900 = 7 days  
 saveValue( "football.data",footballlock )  
 --reset the footbal data to 0  
 storyboard.gotoScene( "maingame", "crossFade", 500 )  
 end  
 end  
end   
 timer.performWithDelay(200, footballcheck, 1)  
  

Thanks Again

Alberto [import]uid: 34105 topic_id: 35429 reply_id: 140923[/import]