HI
i have an array which reads
surah1=(people[1].downloaded)
or for example
surah1=(people[5].downloaded)
how can i change this into a single integer variable
it seems that when processing my surah1 variable it is still acting like an array
thankyou
HI
i have an array which reads
surah1=(people[1].downloaded)
or for example
surah1=(people[5].downloaded)
how can i change this into a single integer variable
it seems that when processing my surah1 variable it is still acting like an array
thankyou
local numString = surah1
local surah1 = tonumber( numString )
ok found solution but how can i change a group of these to integer with a for next loop
thanks so much
surah1=(people[1].downloaded)
surah2=(people[2].downloaded)
surah3=(people[3].downloaded)
surah4=(people[4].downloaded)
surah5=(people[5].downloaded)
surah6=(people[6].downloaded)
surah7=(people[7].downloaded)
surah8=(people[8].downloaded)
surah9=(people[9].downloaded)
surah10=(people[10].downloaded)
nope variable is still acting abnormal when i test on ipad, the conversion to number below
works fine in simulator but when i test on ipad it does not work
local numString = surah1
local surah1 = tonumber( numString )
if i do
surah1=0
this works on both simulator and ipad
please help…
Lua has no “good” way to set variables directly with a name. Why can’t you just use people[i].downloaded?
im obtaining the
surah1=(people[1].downloaded) ; surah2=(people[2].downloaded) ; etc etc etc
from a sqlite database in a loop
and cant access the (people[1].downloaded) from outside the loop
please help…
How about something like this:
local fetchedPeopleData local function obtainPeopleFromSQLiteThingamabob() (your code here) fetchedPeopleData = yourFetchedResult end
if it helps this is how the variables are stored
local people = {} – Begins empty
for row in db:nrows("SELECT * FROM test ") do
print( "Row " … row.id… " “…row.surahnumber…” “…row.surahname…” “…row.downloaded…” “…row.website…” ")
– Create table at the next available array index
people[#people+1] = { rowid=row.id, surahnumber=row.surahnumber, surahname=row.surahname, downloaded=row.downloaded, website=row.website }
end
surah1=(people[1].downloaded) ; surah2=(people[2].downloaded) ; surah3=(people[3].downloaded) ; surah4=(people[4].downloaded) ; surah5=(people[5].downloaded) ; surah6=(people[6].downloaded) ; surah7=(people[7].downloaded) ; surah8=(people[8].downloaded) ; surah9=(people[9].downloaded) ; surah10=(people[10].downloaded) ;
I’ve only skimmed this so I’m sorry if I’m totally wrong.
I’ve had similar issues in the past like this.
have you tried this:
people[“1”].downloaded
Could it be indexing it as a string rather than an int? Would lua do that?
I believe the issue is that @akhtarx5 can’t store his SQLite data in a table 'cause it goes out of scope.
In which case, you should be able to do this:
local people = {} -- Begins empty local function getPeople() for row in db:nrows("SELECT \* FROM test ") do people[#people+1] = { rowid=row.id, surahnumber=row.surahnumber, surahname=row.surahname, downloaded=row.downloaded, website=row.website } end end
That way, people is a variable outside the fetch function, and you can just use the getPeople() function to load the data into the people variable.
caleb p
sorry how would i use the function you provided
how do i setup function correctly, im doing this at the moment
_local sqlite3 = require( “sqlite3” )
local path = system.pathForFile( “surahdata.db”, system.DocumentsDirectory )
local db3 = sqlite3.open( path )
local people = {} – Begins empty
local function getPeople()
for row in db3:nrows("SELECT * FROM test ") do
people[#people+1] = { rowid=row.id, surahnumber=row.surahnumber, surahname=row.surahname, downloaded=row.downloaded, website=row.website }
end
end
getpeople (surah1=(people[1].downloaded) — <<<<<<<<< how do i correct this
print (surah1)_
local numString = surah1
local surah1 = tonumber( numString )
ok found solution but how can i change a group of these to integer with a for next loop
thanks so much
surah1=(people[1].downloaded)
surah2=(people[2].downloaded)
surah3=(people[3].downloaded)
surah4=(people[4].downloaded)
surah5=(people[5].downloaded)
surah6=(people[6].downloaded)
surah7=(people[7].downloaded)
surah8=(people[8].downloaded)
surah9=(people[9].downloaded)
surah10=(people[10].downloaded)
nope variable is still acting abnormal when i test on ipad, the conversion to number below
works fine in simulator but when i test on ipad it does not work
local numString = surah1
local surah1 = tonumber( numString )
if i do
surah1=0
this works on both simulator and ipad
please help…
Lua has no “good” way to set variables directly with a name. Why can’t you just use people[i].downloaded?
im obtaining the
surah1=(people[1].downloaded) ; surah2=(people[2].downloaded) ; etc etc etc
from a sqlite database in a loop
and cant access the (people[1].downloaded) from outside the loop
please help…
How about something like this:
local fetchedPeopleData local function obtainPeopleFromSQLiteThingamabob() (your code here) fetchedPeopleData = yourFetchedResult end
if it helps this is how the variables are stored
local people = {} – Begins empty
for row in db:nrows("SELECT * FROM test ") do
print( "Row " … row.id… " “…row.surahnumber…” “…row.surahname…” “…row.downloaded…” “…row.website…” ")
– Create table at the next available array index
people[#people+1] = { rowid=row.id, surahnumber=row.surahnumber, surahname=row.surahname, downloaded=row.downloaded, website=row.website }
end
surah1=(people[1].downloaded) ; surah2=(people[2].downloaded) ; surah3=(people[3].downloaded) ; surah4=(people[4].downloaded) ; surah5=(people[5].downloaded) ; surah6=(people[6].downloaded) ; surah7=(people[7].downloaded) ; surah8=(people[8].downloaded) ; surah9=(people[9].downloaded) ; surah10=(people[10].downloaded) ;
I’ve only skimmed this so I’m sorry if I’m totally wrong.
I’ve had similar issues in the past like this.
have you tried this:
people[“1”].downloaded
Could it be indexing it as a string rather than an int? Would lua do that?
I believe the issue is that @akhtarx5 can’t store his SQLite data in a table 'cause it goes out of scope.
In which case, you should be able to do this:
local people = {} -- Begins empty local function getPeople() for row in db:nrows("SELECT \* FROM test ") do people[#people+1] = { rowid=row.id, surahnumber=row.surahnumber, surahname=row.surahname, downloaded=row.downloaded, website=row.website } end end
That way, people is a variable outside the fetch function, and you can just use the getPeople() function to load the data into the people variable.
caleb p
sorry how would i use the function you provided
how do i setup function correctly, im doing this at the moment
_local sqlite3 = require( “sqlite3” )
local path = system.pathForFile( “surahdata.db”, system.DocumentsDirectory )
local db3 = sqlite3.open( path )
local people = {} – Begins empty
local function getPeople()
for row in db3:nrows("SELECT * FROM test ") do
people[#people+1] = { rowid=row.id, surahnumber=row.surahnumber, surahname=row.surahname, downloaded=row.downloaded, website=row.website }
end
end
getpeople (surah1=(people[1].downloaded) — <<<<<<<<< how do i correct this
print (surah1)_