newbie question - why would a simple:
local a=display.newLine(0,240,160,240)
throw up the following error:
attempt to index global 'display'
? If I move the command BEFORE my functions it works. If I place it after my functions, it doesn't ?
Label: corona android iphone ipad building error inmobi problem display screen View image tableView failed object physics touch button game lua config event listener |
newbie question - why would a simple:
local a=display.newLine(0,240,160,240)
throw up the following error:
attempt to index global 'display'
? If I move the command BEFORE my functions it works. If I place it after my functions, it doesn't ?
Post plug and play, please? :)
peach, this is weird. I'm a newbie with Lua and am wondering where I place the functions in my code and where I place the rest.
For example if I place the
local star = display.newLine(0,220,100,220) BEFORE my functions it works
if I place the line above AFTER my functions it doesn't work. I'm not calling any of my functions, and I've commented the rest of my code out out.
Do I take it, functions should be placed at the end of my main.lua ?
Hey again,
No, functions don't have to be placed at the end of your main.lua file.
How many lines of code have you got in your file?
If it isn't ridiculously long I can take a look and try to see what is up for you - there shouldn't be any issue regardless of where you place that line of code unless something else is interfering somehow.
Peach :)
here you go Peach. Like I say I'm only just learning Lua now, so it's probably really obvious! I tried to pin point the line where this error appears, so worked back over and it begins with this bit of code.
The error I get is "attempt to call gloabl "bytes_to_s16"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | -- open file mypath = system.pathForFile( "file.raw", system.ResourceDirectory ) f = assert(io.open(mypath, "rb")) while true do --read 2 bytes of file at a time local bytes = f:read(2) if not bytes then break end local high_byte, low_byte = string.byte(bytes, 1, 2) --convert the 2 bytes sample = bytes_to_s16 (low_byte,high_byte) -- save table.insert(samples_s16, sample) end -- close the file io.close (f) -- convert function bytes_to_s16 (hb, lb) local u16 = hb * 256 + lb return (hb > 127) and (u16 - 65536) or u16 end |
Arrrgggghhh!!! I've sorted it!
Had my own function called display() and it was messing with Corona.
I'm an idiot! (but learning all the while)
Thanks Peach
Haha, you aren't an idiot - you're just still learning :)
Also careful when you post, if you do a "<" follow by "a" it will make your text whacked out like above.
Peach :)