[SOLVED] Help listing information about that person? For my Science Fair Project

@budershank yes that is 100% true I dont have knowledge in SQL lite :(. Learning something like that requires someone to teach it to me in which there is no that has time that can. But no matter someday It will come to me nothing is impossible.

But anyways thanks so much I’m going to test it now. Does this display a list of their information when i do it with more than 1 person? [import]uid: 17058 topic_id: 30943 reply_id: 123761[/import]

No, this just lets you 1) record the info and 2) get all of the scores back via a Lua table. From there you should be able to use which ever method you would like to display it on the screen(such as scrollview/tableview or whatever). I would think about how you want to display the information and then pick the appropriate method. If you are trouble getting that to work then im sure someone on the forums(maybe me) can help.

Really, though, displaying that data can be one of the last things you work on. It would make more sense to have the reaction time portion done as well as your saving done first. It will prevent you from having to go back and make changes in case you realize you wanted to record another piece of information(such as gender, though that would be silly as we all clearly know men would be better at it). [import]uid: 147305 topic_id: 30943 reply_id: 123762[/import]

Well I’am still struggling to get this with my poor knowledge of SQL it becomes burden to me to understand something simple as you see it but I don’t.

I’am struggling as in inserting their data by having them type on. I’m a clueless of how to do that.

I started out from this

local playerName = "budershank"  
local playerAge = 99  
local playerTime = 1.4  
addReactionTime(playerName, playerAge, playerTime)  
local defaultField  
local answer = ""  
print(playerName)  
print(playerAge)  
print(playerTime)  
  
local function checkAnswer(answer, enteredAnswer)  
 local results = false  
  
 if string.lower(answer) == string.lower(enteredAnswer) then  
 results = true  
 end  
  
 return results  
end  
  
local function fieldHandler( event )  
 if ( "ended" == event.phase or "submitted" == event.phase) then  
 if checkAnswer(answer, event.target.text) == true then  
  
 print(answer)  
 -- Hide keyboard  
 native.setKeyboardFocus( nil )  
 else  
  
  
  
 -- Hide keyboard  
 native.setKeyboardFocus( nil )  
 end  
 end  
  
 return true  
end  
   
-- Create our Text Field  
defaultField = native.newTextField( 85, 45, 50, 30 ) -- passes the text field object  
defaultField:addEventListener("userInput", fieldHandler)  

How would I have that typed information saved? [import]uid: 17058 topic_id: 30943 reply_id: 123767[/import]

Well, the beauty of the code I gave you is you don’t need any SQL knowledge. All you need to know is that using addReactionTime(playerName, playerAge, playerTime) records your data and getScores() retrieves it for you.

Looks like what you are doing above is probably copied from the documents. Scrap that code. What you need are two text boxes and a button. The user types in their age and name and clicks the button, which then saves the data. Think of it just like when you sign up for something or you are entering a username/password. example:

[lua]-- create the text fields and button
txtName = native.newTextField( 85, 45, 50, 30 )
txtAge = native.newTextField( 85, 45, 50, 60 )

btnSave = widget.newButton{
label=“Play”,
labelColor = { default={0}, over={255} },
fontSize = 25,
width=100, height=50,
onRelease = onSaveClick – event listener function
}
btnSave.x = display.contentWidth /2
btnSave.y = 90

– the event that is fired when you press the button
function onSaveClick(event)
–get the name text and put it in a variable
local playerName = txtName.text
local playerAge = txtAge.text
–the last variable is their reaction time, which you should stored in a variable already, lets call it playerReactionTime.

addReactionTime(playerName, playerAge, playerReactionTime)

end[/lua]

I would suggest that your users enter this information after they have already had their reaction time tested. [import]uid: 147305 topic_id: 30943 reply_id: 123770[/import]

I’m sorry to bother you again but when I type in the information on the box it does not print in terminal. I try it print in the terminal but nothing is showing.

I know there is something I’m doing wrong I did it like this

[code]
local widget = require “widget”

– create the text fields and button
txtName = native.newTextField( 85, 240, 50, 30 )
txtAge = native.newTextField( 85, 45, 50, 30 )

btnSave = widget.newButton{
label=“Play”,
labelColor = { default={0}, over={255} },
fontSize = 25,
width=100, height=50,
onRelease = onSaveClick – event listener function
}
btnSave.x = display.contentWidth /2
btnSave.y = 90

– the event that is fired when you press the button
local onSaveClick = function (event)
if event.phase == “release” then
–get the name text and put it in a variable
local playerName = txtName.text
local playerAge = txtAge.text
print(playerName)
print(playerAge)
–the last variable is their reaction time, which you should stored in a variable already, lets call it playerReactionTime.

addReactionTime(playerName, playerAge, playerReactionTime)
end
end
[/code] [import]uid: 17058 topic_id: 30943 reply_id: 123778[/import]

when I click on play I’m getting an error

about this code:

 local sqlInsertScore =[[INSERT INTO SCORES VALUES ( ']]..strName..[[',]]..intAge..[[,]]..realTime..[[);]]  

The error is saying this about this code: attempt to concatenate local ‘realTime’ (a nil value) i
n function 'addReactionTim

Also the error is saying something about this code

addReactionTime(playerName, playerAge, playerReactionTime)  

The error is saying this about this code: in function ‘onRelease’ [import]uid: 17058 topic_id: 30943 reply_id: 123808[/import]

Ah, need to put the onSaveClick function before the button declaration. If you do that it will print for you. You will receive an error because you don’t have a playerReactionTime yet, but you should get that once you have the actual sciency part done.
EDIT:

Apparently we posted at the same time. See what I just said about the error above. If you just wanted to test it just define your playerReactionTime somewhere in your code, such as playerReactionTime = 1.4. [import]uid: 147305 topic_id: 30943 reply_id: 123809[/import]

Yes the name and age printed success but now there is few thing that I cant get is retrieving the data I saved how would I use getScore() properly?

[import]uid: 17058 topic_id: 30943 reply_id: 123845[/import]

Basically the getScores() will return a table with the information. Below would be an example of getting the table and then iterating through it and printing the data. Since it’s in a lua table it should be much easier to figure out how to use it since most Corona examples involve using a table.
[lua]local myScoreTable = getScores()

for i, line in ipairs(myScoreTable) do

print("Name: “…myScoreTable[i].name…” Age: “…myScoreTable[i].age… " Reaction Time:”…myScoreTable[i].reactionTime)

end[/lua]

Also, don’t have any of my code with me so hopefully my syntax is ok :open_mouth: [import]uid: 147305 topic_id: 30943 reply_id: 123869[/import]

yes I was able to get I think was it like this?

local myScoreTable = getScores()  
   
for i = 1, 4 do  
   
print("Name: "..myScoreTable[i].name.." Age: "..myScoreTable[i].age.. " Reaction Time:"..myScoreTable[i].reactionTime)  
   
end  

Also strangely it prints out this
Name: budershank Age: 99 Reaction Time:1.4
Name: budershank Age: 99 Reaction Time:1.4
Name: budershank Age: 99 Reaction Time:1.4
Name: budershank Age: 99 Reaction Time:1.4

I’m wondering how that data is in there?

EDIT: I know how that got there I also notice that when insert my name and age in the textboxes it does not save becasue when I change the number from i = 1, 5 to i = 1, 6 I get an error but if I insert both textboxes in numbers the data is saved how come?
[import]uid: 17058 topic_id: 30943 reply_id: 123878[/import]

Well, I’m not going to answer your question first…

To clear out the database on your simulator go to the File Menu > show project sandbox and delete the database file. On your device you can just uninstall it then reinstall(must uninstall!). That’s how you can get any of your test data out, like my budershank stuff!

Any reason why you switched the for loop from the ipairs to for 1,4? since your table size is going to continue to grow you really don’t want to use hard numbers. At minimum I would do for i, table.getn(myScoreTable) so it goes through all of your records.

The reason you get errors when not using numbers is because we are telling the database to expect numbers. Most technologies are very strict about data types, such as integer, string, decimal, dates etc. You might think hey, it’s just easier using strings/text all the time but you will be shooting yourself in the foot. The great thing about doing the numbers is it is easy to sort them properly, like if you wanted to display who has the fastest reaction time. [import]uid: 147305 topic_id: 30943 reply_id: 123889[/import]

I understood the post #10 you did I thought what you gave me there was for me to change it. I did not know it was suppose to be like that.

I used your example in #10 and still the same problem. With the number only working and not text.

What I have it like this

local myScoreTable = getScores()  
   
 for i, line in ipairs(myScoreTable) do   
   
print("Name: "..myScoreTable[i].name.." Age: "..myScoreTable[i].age.. " Reaction Time:"..myScoreTable[i].reactionTime)  
   
end  

Same as yours but the problem still persists

When I do this I get an error

local myScoreTable = getScores()  
   
 for i, line in ipairs table.getn(myScoreTable) do   
   
print("Name: "..myScoreTable[i].name.." Age: "..myScoreTable[i].age.. " Reaction Time:"..myScoreTable[i].reactionTime)  
   
end  

[import]uid: 17058 topic_id: 30943 reply_id: 123891[/import]

The second example you gave is just wrong, first one should work.

At this point I’m confused on where the problem is. At what point do you receive an error and what is the error? [import]uid: 147305 topic_id: 30943 reply_id: 123893[/import]

Ok i see when I post name and age it prints out but when i try to retrieve it it does not retrieve the data

Why is that?

I have both the getScore()

and the text boxes to submit age and name in the same menu.lua is that what causing not to retrieve?

EDIT: Duh the problem was I kept on putting my name in the wrong text box and age in the wrong text box that why it was not retrieving I’m such an idiot.

Oh one and thing I’m so sorry but to have the time retrieve in other scenes do I follow the same method for getScore() right? Is not to modify the score but to test the people with 5-10 different scenes for the time to be submitted with their name and age. [import]uid: 17058 topic_id: 30943 reply_id: 123894[/import]

If you put it in your main.lua you can use the function anywhere in the app. In a real design it wouldn’t be the best way to do it but given the scale and simplicity who cares.

Currently it’s not tracking at a per scene level but just at a global level. If you need it by scene that’s not a big deal, just will mean an extra variable that you pass into the saving function. [import]uid: 147305 topic_id: 30943 reply_id: 123897[/import]

I’m sorry I got lost with what you said for placing the playerReactionTime can you please further detail it for me.

[import]uid: 17058 topic_id: 30943 reply_id: 123900[/import]

Hey I think I got the playerReactionTime with a method I remember that works with this. But anyways thank you sooooooooooooooo much in helping me. This was a really big important thing for me to have. I appreciate your help, and the time you took to help. Thanks and have a nice day

:slight_smile:

[import]uid: 17058 topic_id: 30943 reply_id: 124038[/import]