Hi guys, so i’ve tried creating a module which chooses a category based on what button is pressed.
For example “Category1” was pressed, in that category1 it displays/asked questions about “internet”, and if a user presses the other button like “Category2” it displays questions about “Food”, and another button which is “Category3” is pressed questions about “Life” is displayed/asked. Of course only 1 button can be pressed and the user must/have to finish the category he went to.
Here is the current code i tried:
local function gameCatHandler(event)
local phase = event.phase
if myData.gameCat == “category1” then
– print(event.target.id)
print(“Category”,myData.categories[event.target.id].ques_no)
myData.gameCat = event.target.id
myData.setBg(1,2)
storyboard.gotoScene(“category1”, {
effect = “fade”,
time = 250,
})
else if myData.gameCat == “category2” then
print(“Category”,myData.categories[event.target.id].ques_no)
myData.gameCat = event.target.id
myData.setBg(1,2)
storyboard.gotoScene(“category2”, {
effect = “fade”,
time = 250,
})
else
print(“Category”,myData.categories[event.target.id].ques_no)
myData.gameCat = event.target.id
myData.setBg(1,2)
storyboard.gotoScene(“category3”, {
effect = “fade”,
time = 250,
})
end
end
return true
end
end
Buttons Code
local screenGroup = self.view
local bgGroup = display.newGroup()
local buttonGroup = display.newGroup()
screenGroup:insert(bgGroup)
screenGroup:insert(buttonGroup)
background = display.newImageRect ( “Images/Bg.png”,565 , _H )
background.x = _W*.5 ; background.y = _H*.5
bgGroup:insert(background)
local btnData = {
{id=“category1”,x=180,y= 25,},
{id=“category2”,x=348,y=160},
{id=“category3”,x=265,y=225},
}
for i = 1, 3 do
local btn = widget.newButton( {
id = btnData[i].id,
x = btnData[i].x,
y = btnData[i].y,
width = 50,
height = 50,
– font = native.systemFont,
– fontSize = 18,
– labelColor = {
– default = {0,0,0},
– over = {255,255,255}
– },
defaultFile = “buttons/”… string.lower(btnData[i].id)… “Press.png”,
overFile = “buttons/”… string.lower(btnData[i].id)… “Pressed.png”,
onRelease = gameCatHandler,
} )
btn.anchorX = 0
btn.anchorY = 0
buttonGroup:insert( btn)
When i use the code for the event handler it doesn’t call properly like for example i pressed the category1 button, the game displays category3 rather than 1. What is the proper code for it?
All questions these categories have is only on 1 Database(SQL), or is it easier to have each categories have an individual database?