Hello everyone, I am having an issue with scrollview. Here is an example of my problem.
The table used if anyone wants it:
utils.settings = {--id, name, value, cost, + table num, image, obj x offset, obj y offset { 1, "balance" , 0, 0 , 0, "", }, { 2, "gamercoin" , 0, 0 , 0, "", }, { 3, "clickervalue" , 1, 0 , 0, "", }, { 4, "autoclicker" , 1, 0 , 0, "", }, { 5, "monitor\_level", 4, 0 , 0, "", }, { 6, "buymouse" , 0, -20, 1, "mouse1", 100, 75 }, --make sure the value increases by three each time :) { 7, "buycpu" , 0, -20, 4, "", }, { 8, "buygpu" , 0, -20, 7, "", }, { 9, "buyram" , 0, -20, 10, "", }, { 10, "buybuilding" , 0, -20, 13, "", }, }
Code:
local objects = {} local function scroll\_listener( event ) local phase = event.phase if ( event.limitReached ) then if ( event.direction == "up" ) then print( "Reached bottom limit" ) elseif ( event.direction == "down" ) then print( "Reached top limit" ) end end return true end local scroll\_view = widget.newScrollView( { top = 60, left = 0, width = width, height = height \* 2, horizontalScrollDisabled = true, verticalScrollDisabled = false, listener = scroll\_listener } ) local function increase\_upgrades( event ) for i = 1, #utils.settings do if ( event.target.string == utils.settings[i][2] ) then if ( utils.settings[1][3] + utils.settings[i][4] \>= 0 ) then --if the users balance + objects cost \>= 0 then if ( objects[utils.settings[i][5]].alpha == 1 ) then --if the object has a alpha value of 1 then if ( event.phase == "began" ) then objects[utils.settings[i][5]].y = objects[utils.settings[i][5]].y + 1.5 end if ( event.phase == "ended" ) then utils.update\_balance( utils.settings[i][4] ) --update the balance by deducting the cost of the object if ( utils.settings[i][6] ~= "" and utils.settings[i][3] \< 1 ) then --if the object can draw an image then utils.settings[i][3] = 1 --these objects only get brought once objects[utils.settings[i][5]].alpha = 0.5 --set alpha to 0.5 objects[utils.settings[i][5] + 1].alpha = 0.5 --set alpha to 0.5 (they now cannot be brought again) objects[utils.settings[i][5] + 2].alpha = 0.5 --set alpha to 0.5 (they now cannot be brought again) elseif ( utils.settings[i][6] == "" ) then --if the object cannot draw an image then utils.settings[i][3] = utils.settings[i][3] + 1 --increase the value of the object by 1 utils.settings[i][4] = utils.settings[i][4] \* 2 --doubling the cost of the object utils.settings[3][3] = utils.settings[3][3] + 1 --increasing the clickervalue by 1 utils.update\_database( utils.settings[3][1], utils.settings[3][2], utils.settings[3][3], utils.settings[3][4] ) --updating the clickervalue to the database end objects[utils.settings[i][5] + 1].text = utils.settings[i][2] .. ": " .. ( -1 \* utils.settings[i][4] ) --updating the text associated with the brought object objects[utils.settings[i][5] + 2].text = "amount: " .. ( utils.settings[i][3] ) utils.update\_database( utils.settings[i][1], utils.settings[i][2], utils.settings[i][3], utils.settings[i][4] ) --updating the objects value in the database objects[utils.settings[i][5]].y = objects[utils.settings[i][5]].y - 1.5 end return true end end end end end for i = 1, #utils.settings do if ( utils.settings[i][4] ~= 0 ) then objects[utils.settings[i][5]] = display.newImage( utils.settings[i][2] .. ".png", center\_x - 60, ( i - 5 ) \* ( height / 4.5 ) - 35 ) sceneGroup:insert( objects[utils.settings[i][5]] ) objects[utils.settings[i][5]]:scale( 0.4, 0.4 ) objects[utils.settings[i][5] + 1] = display.newText( utils.settings[i][2] .. ": " .. ( -1 \* utils.settings[i][4] ), center\_x - 10, ( i - 5 ) \* ( height / 4.5 ) - 35, font, 24 ) sceneGroup:insert( objects[utils.settings[i][5] + 1] ) objects[utils.settings[i][5] + 1].anchorX = 0 objects[utils.settings[i][5] + 2] = display.newText( "amount: " .. ( utils.settings[i][3] ), objects[utils.settings[i][5] + 1].x, objects[utils.settings[i][5] + 1].y + 17, font, 16 ) sceneGroup:insert( objects[utils.settings[i][5] + 2] ) objects[utils.settings[i][5] + 2].anchorX = 0 if ( utils.settings[i][3] == 1 and utils.settings[i][6] ~= "" ) then --when switching to "upgrades.lua" draw the image & text to .alpha(0.5) if only able to be brought once objects[utils.settings[i][5]].alpha = 0.5 objects[utils.settings[i][5] + 1].alpha = 0.5 objects[utils.settings[i][5] + 2].alpha = 0.5 end objects[utils.settings[i][5]].string = utils.settings[i][2] scroll\_view:insert( objects[utils.settings[i][5]] ) scroll\_view:insert( objects[utils.settings[i][5] + 1] ) scroll\_view:insert( objects[utils.settings[i][5] + 2] ) objects[utils.settings[i][5]]:addEventListener( "touch", increase\_upgrades ) end end sceneGroup:insert( scroll\_view )
Any help would be greatly appreciated!