I need help on this very important part of my game ok so this is what I’m doing is when a person plays a game they start with the game with 30 bullets. What I’m trying to do is when they go to the shop and buy upgrade bullets, now when they buy it they now can hold 60 bullets. This is how I have it setup
shop.lua
[code]module(…, package.seeall)
– Main function - MUST return a display.newGroup()
function new()
local localGroup = display.newGroup()
gameState = require(“GameState”)
if(gameState.money == nil) then
gameState.money = 0
–other init code can go here
end
local bankText2 = display.newText("", 160, 30,“Arial”,20)
bankText2.text = “$”… gameState.money
localGroup:insert(bankText2)
local box = display.newRect(160, 240, 30, 30)
localGroup:insert(box)
local box2 = display.newRect(10, 10, 30, 30)
localGroup:insert(box2)
local box3 = display.newRect(250, 160, 30, 30)
localGroup:insert(box3)
local box4 = display.newRect(300, 160, 30, 30)
localGroup:insert(box4)
local bankText = display.newText("", 160, 30,“Arial”,20)
localGroup:insert(bankText)
local highText = display.newText("", 0,0,“Arial”,22)
highText.x = display.contentWidth/2
highText.y = 100
localGroup:insert(highText)
local function change ()
if gameState.money > 59 then
gameState.money = gameState.money - 1
bankText2.text = “$”… gameState.money
saveFile(“twinb.txt”, 1)
saveFile(“extra.txt”, 2) — Right here is were it changes
print(“Bought!”)
elseif gameState.money <= 59 then
print(“Not enough!”)
end
end
box:addEventListener(“tap”, change)
return localGroup
end[/code]
game.lua
[code] local function powertwin2 ()
extrabull = loadFile (“extra.txt”)
if extrabull == “empty” then
extrabull = 1
saveFile(“extra.txt”, extrabull)
end
end
powertwin2()
local function bulletsgood()
if tonumber(extrabull) == 1 then
local limits = 30
local limitsbullet = display.newText(“Ammo:30”, 30, 30,“Arial”, 18)
localGroup:insert(limitsbullet)
end
end
Runtime:addEventListener( “enterFrame”, bulletsgood)
local function bulletsgood2()
if tonumber(extrabull) == 2 then
local limits = 60
local limitsbullet = display.newText(“Ammo:60”, 30, 30,“Arial”, 18)
localGroup:insert(limitsbullet)
end
end
bulletsgood2()
local function shoot (event) – This function is when they shoot
if limits == 0 then
great = true
end
if event.phase == “release” then
if great == false then
if tonumber(twinb) == 1 then
local bullet = display.newImageRect(“bullet.png”, 10, 10)
bullet.x = heli.x + 40
bullet.y = heli.y
bullet.hit = “bullet”
bullet.isFixedRotation = true
transition.to (bullet, {time = 2000, x=550})
physics.addBody (bullet, {bounce=0.6})
limits = limits - 1
limitsbullet.text = “Ammo:” …limits
localGroup:insert(bullet)
bullet:addEventListener(“collision”, bullet)
function bullet:collision (event)
if event.other.hit ~= “heli” then
bullet:removeSelf()
end
end
elseif tonumber(twinb) == 2 then
local twin = display.newImageRect(“bullet.png”, 10, 10)
twin.x = heli.x + 40
twin.y = heli.y
twin.hit = “twin”
twin.isFixedRotation = true
transition.to (twin, {time = 2000, x=550})
physics.addBody (twin, {bounce=0.6})
localGroup:insert(twin)
local twin2 = display.newImageRect(“bullet.png”, 10, 10)
twin2.x = heli.x + 40
twin2.y = heli.y + 15
twin2.hit = “twin”
twin2.isFixedRotation = true
transition.to (twin2, {time = 2000, x=550})
physics.addBody (twin2, {bounce=0.6})
localGroup:insert(twin2)
twin:addEventListener(“collision”, twin)
function twin:collision (event)
if event.other.hit ~= “heli” then
twin:removeSelf()
twin2:removeSelf()
end
end
elseif tonumber(twinb) == 3 then
local bullet3 = display.newImageRect(“bullet.png”, 20, 20)
bullet3.x = heli.x + 40
bullet3.y = heli.y
bullet3.hit = “bullet3”
bullet3.isFixedRotation = true
transition.to (bullet3, {time = 2000, x=550})
physics.addBody (bullet3, {bounce=0.6})
localGroup:insert(bullet3)
bullet:addEventListener(“collision”, bullet3)
function bullet:collision (event)
if event.other.hit ~= “heli” then
bullet3:removeSelf()
end
end
end
end
end
end
ButtonA = ui.newButton{
default = “buttonoverA.png”,
over = “buttonA.png”,
x = 360,
y = 280,
onEvent = shoot,
}
localGroup:insert(ButtonA)
[/code]
I use ego. I’m trying to have this work because is very important to my game [import]uid: 17058 topic_id: 22814 reply_id: 322814[/import]
[import]uid: 52491 topic_id: 22814 reply_id: 91204[/import]