Basically I am not sure how to define Items on line 4 and 27. If someone can help me that would be great. It just says in the output, unknown global "Items".
for i,v in pairs(Buttons:GetChildren()) do
local NewItem = BoughtItems:FindFirstChild(v.Item.Value)
if NewItem ~= nil then
Items[NewItem.Name] = NewItem:Clone()
NewItem:Destroy()
else
v.Transparency = 1
v.CanCollide = false
end
if v:FindFirstChild("Dependency") then
coroutine.resume(coroutine.create(function()
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
if BoughtItems:WaitForChild(v.Dependency.Value, 100000) then
v.ButtonPart.Transparency = 0
v.ButtonPart.CanCollide = true
end
end))
end
v.ButtonPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Values.OwnerValue.Value == Player then
if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then
if Player:WaitForChild("leaderstats").Cash.Value >= v.Price.Value then
Player.leaderstats.Cash.Value -= v.Price.Value
Items[v.Item.Value].Parent = BoughtItems
v:Destroy()
end
end
end
end
end)
end
Related
I am currently in the process of making a game known as Elf Tycoon. This game involves the player buying elves, (dummy character rigs as placeholders). These characters are then aligned in rows of 8, going on forever. I am having an issue with the system. It seems that every floor apart from the first has its first elf slightly lower than the others. Attached is a screenshot of the issue, and the code is below.
local elvesFolder = script.Parent.Elves
local elfValues = script.Parent.ElfValues
local tycoonLevel2 = script.Parent:FindFirstChild("Tycoon Level 2")
local repStorage = game:GetService("ReplicatedStorage")
local tycoonRoof = script.Parent["Tycoon Roof"]
local currentNumberOfFloors = 1
local currentLevel = 2
local elves = 60
local remainingElves = 60
local number_of_floors = math.floor(elves/9)-1
local tierOneElf = script.Parent.Elves:FindFirstChild("T1 Elf")
local function ResetTycoon()
for i,v in pairs(elvesFolder:GetChildren()) do
v:Destroy()
end
for i,v in pairs(script.Parent:GetChildren()) do
if v.Name == "New Tycoon Level" or v.Name == "Tycoon Level 2" then
v:Destroy()
end
end
end
local function ResetElves()
remainingElves = elves
number_of_floors = math.floor(elves/9)+1
if elves <= 9 then
number_of_floors = 1
end
if number_of_floors >= 2 then
local levelTwo = repStorage:FindFirstChild("Tycoon ".. script.Parent.Name:split(" ")[2] .." Level 2")
if levelTwo then
local newLevel = levelTwo:Clone()
newLevel.Parent = script.Parent
newLevel.Name = "Tycoon Level 2"
end
end
for i = 1,number_of_floors do
if i >= 3 then
local newFloor = tycoonLevel2:Clone()
newFloor.Name = "New Tycoon Level"
newFloor.Parent = script.Parent
for a,b in pairs(newFloor:GetDescendants()) do
if b:IsA("Part") or b:IsA("MeshPart") then
b.Position += Vector3.new(0,7.9*(i-2),0)
end
end
end
for a,b in pairs(tycoonRoof:GetDescendants()) do
if b:IsA("Part") or b:IsA("BasePart") then
b.Position = Vector3.new(b.Position.X,28+7.9*(i-1),b.Position.Z)
end
end
for j = 1,9 do
if j == 1 then
local newElf = repStorage["Tycoon ".. script.Parent.Name:split(" ")[2] .." T1 Elf"]:Clone()
newElf.Name = "T1 Elf"
newElf.Parent = elvesFolder
if i ~= 1 then
for a,b in pairs(newElf:GetDescendants()) do
if b:IsA("Part") or b:IsA("BasePart") then
b.Position += Vector3.new(0,7.9*(i-1),0)
end
end
end
remainingElves -= 1
else
if remainingElves >= 1 then
local newestElf = nil
for a,b in pairs(elvesFolder:GetChildren()) do
newestElf = b
end
local newElf = newestElf:Clone()
newElf.Name = "T1 Elf"
newElf.Parent = elvesFolder
newElf:MoveTo(Vector3.new(newElf.PrimaryPart.Position.X,newElf.PrimaryPart.Position.Y,newElf.PrimaryPart.Position.Z)+(-newElf.PrimaryPart.CFrame.RightVector*6))
end
remainingElves -= 1
end
end
end
end
Note: This is only the first function in the script. This is where the issue would be occurring. Thanks for any help that you can provide!
Here is that screenshot. The expected result is to have all of the elves aligned properly for each floor:
This script allows people to produce meth, starting production will succeed when you have the right amount of objects in your inventory.
Only when you don't have the right amount you should get a notification and you don't get that notification..
Following error pops up: SCRIPT ERROR: #ns-meth/server.lua:18: Attempt to index a nil value.
Code:
RSCore = nil
Citizen.CreateThread(function()
while RSCore == nil do
TriggerEvent('RSCore:GetObject', function(obj) RSCore = obj end)
Citizen.Wait(0)
end
end)
RegisterServerEvent('RSCore_methcar:start')
AddEventHandler('RSCore_methcar:start', function()
local src = source
local Player = RSCore.Functions.GetPlayer(src)
local amount = 0
if Player.Functions.GetItemByName('acetone').amount >= 5 and Player.Functions.GetItemByName('lithium').amount >= 2 and Player.Functions.GetItemByName('methlab').amount >= 1 then
TriggerClientEvent('RSCore_methcar:startprod', src)
Player.Functions.RemoveItem('acetone', 5)
Player.Functions.RemoveItem('lithium', 2)
else
if Player.Functions.GetItemByName('acetone').amount <= 4 and Player.Functions.GetItemByName('lithium').amount <= 1 and Player.Functions.GetItemByName('methlab').amount <= 0 then
RSCore.Functions.Notify("Je hebt niet de juiste benodigdheden!", "error")
end
end
end)
RegisterServerEvent('RSCore_methcar:stopf')
AddEventHandler('RSCore_methcar:stopf', function(id)
local src = source
local Players = RSCore.GetPlayers()
local Player = RSCore.Functions.GetPlayer(src)
for i=1, #Players, 1 do
TriggerClientEvent('RSCore_methcar:stopfreeze', Players[i], id)
end
end)
RegisterServerEvent('RSCore_methcar:make')
AddEventHandler('RSCore_methcar:make', function(posx,posy,posz)
local src = source
local Player = RSCore.Functions.GetPlayer(src)
if Player.Functions.GetItemByName('methlab').amount >= 1 then
local Players = RSCore.Functions.GetPlayer(src)
for i=1, #Players, 1 do
TriggerClientEvent('RSCore_methcar:smoke',Players[i],posx,posy,posz, 'a')
end
else
TriggerClientEvent('RSCore_methcar:stop', src)
end
end)
RegisterServerEvent('RSCore_methcar:finish')
AddEventHandler('RSCore_methcar:finish', function(qualtiy)
local src = source
local Player = RSCore.Functions.GetPlayer(src)
print(qualtiy)
local rnd = math.random(-5, 5)
TriggerEvent('KLevels:addXP', src, 20)
Player.Functions.AddItem('meth', math.floor(qualtiy / 2) + rnd)
end)
RegisterServerEvent('RSCore_methcar:blow')
AddEventHandler('RSCore_methcar:blow', function(posx, posy, posz)
local src = source
local Players = RSCore.GetPlayers()
local Player = RSCore.Functions.GetPlayer(src)
for i=1, #Players, 1 do
TriggerClientEvent('RSCore_methcar:blowup', Players[i],posx, posy, posz)
end
Player.removeInventoryItem('methlab', 1)
end)
RegisterServerEvent('ns-meth:server:callCops')
AddEventHandler('ns-meth:server:callCops', function(streetLabel, coords)
local msg = "Er is een verdachte situatie op "..streetLabel..", mogelijks drugs productie."
local alertData = {
title = "Verdachte situatie",
coords = {x = coords.x, y = coords.y, z = coords.z},
description = msg
}
for k, v in pairs(RSCore.Functions.GetPlayers()) do
local Player = RSCore.Functions.GetPlayer(v)
if Player ~= nil then
if (Player.PlayerData.job.name == "police" and Player.PlayerData.job.onduty) then
TriggerClientEvent("ns-meth:client:robberyCall", Player.PlayerData.source, msg, streetLabel, coords)
TriggerClientEvent("rs-phone:client:addPoliceAlert", Player.PlayerData.source, alertData)
end
end
end
end)
Can someone tell me how can I fix this error that shows up when I run my script? Thanks
line 4: Workspace.Slide1.PointsPart.Script:4: attempt to index nil with 'leaderstats'
script.Parent.Touched:Connect(function(hit)
local player = hit.Parent:FindFirstChild("Humanoid")
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.leaderstats.Points.Value >= 0 then
wait()
script.Disabled = true
script.Parent.Transparency = 1
script.Parent.CanCollide = false
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value +5
wait(0.5)
script.Parent.Transparency = 1
script.Parent.CanCollide = false
script.Disabled = false
end
end)
The Touched event fires for anything that touches the part. You are not handling the case that a part isn't a child of a Player's Character.
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if not plr then
return
end
if plr.leaderstats.Points.Value >= 0 then
You could change it to this
script.Parent.Touched:Connect(function(hit)
local player = hit.Parent:FindFirstChild("Humanoid")
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr and plr.leaderstats.Points.Value >= 0 then
wait()
script.Disabled = true
script.Parent.Transparency = 1
script.Parent.CanCollide = false
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value +5
wait(0.5)
script.Parent.Transparency = 1
script.Parent.CanCollide = false
script.Disabled = false
end
end)
the compiler will calculate the instance "plr" first,
if it isn't nil, then the compiler will calculate "plr.leaderstats.Points.Value >= 0"
and this process called "Short-Circuit Evaluation"
I am creating a 2d game using Corona to practice coding, and I am stuck on a problem. The back of one of the enemies in the game, is shaped like a bumpy slide(sort of), when my character hits the enemy on its back, it begins to slide off of the screen. When an enemy is hit, the game switches to another screen and switches back.
https://www.youtube.com/watch?v=xGoZ1jEG0YA&feature=youtu.be
This is a video that shows what is happening, at around 40 or 45 seconds you will see the character begin to slide.
I have tried multiple things to fix this, both the bounce factor of the enemies and player is set to zero. I tried setting the linearVelocity of the player's x coordinate to zero, but that did not work. This is my code for collision detection.
function spawnEnemies()
temp = math.random(1, 4)
enemy = display.newSprite(beetle, beetleSequenceData)
enemy.x = _R + 100
enemy.y = _CY
enemy.hasBeenScored = false
physics.addBody(enemy, "dynamic", physicsData:get("beetle"))
enemy.xScale = -1
enemy.id = "enemy"
enemy.isFixedRotation = true
enemy:play()
group:insert(enemy)
enemy2 = display.newSprite(vulture, vultureSequenceData)
enemy2.x = _R + 100
enemy2.y = _CY - (enemy2.height * 0.25)
enemy2.hasBeenScored = false
physics.addBody(enemy2, "dynamic", physicsData:get("vulture"))
enemy2.xScale = -1
enemy2.gravityScale = -0.01
enemy2.id = "enemy2"
enemy2.isFixedRotation = true
enemy2:play()
specialGroup:insert(enemy2)
enemy3 = display.newSprite(scorpion, scorpionSequenceData)
enemy3.x = _R + 100
enemy3.y = _CY
enemy3.hasBeenScored = false
physics.addBody(enemy3, "dynamic", physicsData:get("scorpion"))
enemy3.xScale = -1
enemy3.id = "enemy3"
enemy3.isFixedRotation = true
enemy3:play()
group:insert(enemy3)
enemy4 = display.newSprite(bee, beeSequenceData)
enemy4.x = _R + 100
enemy4.y = _CY - (enemy4.height * 0.25)
enemy4.hasBeenScored = false
physics.addBody(enemy4, "dynamic", floatingEnemies:get("bee"))
enemy4.xScale = -1
enemy4.gravityScale = -0.01
enemy4.id = "enemy4"
enemy4.isFixedRotation = true
enemy4:play()
specialGroup:insert(enemy4)
if temp == 1 then
enemy2:removeSelf()
enemy3:removeSelf()
enemy4:removeSelf()
elseif temp == 2 then
enemy:removeSelf()
enemy3:removeSelf()
enemy4:removeSelf()
elseif temp == 3 then
enemy:removeSelf()
enemy2:removeSelf()
enemy4:removeSelf()
else
enemy:removeSelf()
enemy2:removeSelf()
enemy3:removeSelf()
end
end
function moveEnemies()
for a = group.numChildren, 1, -1 do
if group[a].x < 100 then
if group[a].hasBeenScored == false then
updateScore()
group[a].hasBeenScored = true
end
end
if group[a].x > _L - 100 then
group[a].x = group[a].x - 8
else
group:remove(group[a])
end
end
for b = specialGroup.numChildren, 1, -1 do
if specialGroup[b].x < 100 then
if specialGroup[b].hasBeenScored == false then
specialUpdateScore()
specialGroup[b].hasBeenScored = true
end
end
if specialGroup[b].x > _L - 100 then
specialGroup[b].x = specialGroup[b].x - 8
else
specialGroup:remove(specialGroup[b])
end
end
end
function onCollision(event)
local function removeOnPlayerHit(obj1, obj2)
if(obj1 ~= nil and obj1.id == "enemy") then
display.remove(obj1)
end
if(obj2 ~= nil and obj2.id == "enemy") then
display.remove(obj2)
end
if(obj1 ~= nil and obj1.id == "enemy2") then
display.remove(obj1)
end
if(obj2 ~= nil and obj2.id == "enemy2") then
display.remove(obj2)
end
if(obj1 ~= nil and obj1.id == "enemy3") then
display.remove(obj1)
end
if(obj2 ~= nil and obj2.id == "enemy3") then
display.remove(obj2)
end
if(obj1 ~= nil and obj1.id == "enemy4") then
display.remove(obj1)
end
if(obj2 ~= nil and obj2.id == "enemy4") then
display.remove(obj2)
end
end
local function showPlayerHit()
local tmr_onPlayerHit = timer.performWithDelay(1, playerHit, 1)
end
if event.phase == "began" then
if((event.object1.id == "enemy" or event.object1.id == "enemy2" or event.object1.id == "enemy3" or event.object1.id == "enemy4") and event.object2.id == "character") then
showPlayerHit()
removeOnPlayerHit(event.object1, nil)
elseif(event.object1.id == "character" and (event.object2.id == "enemy" or event.object2.id == "enemy2" or event.object2.id == "enemy3" or event.object2.id == "enemy4")) then
showPlayerHit()
removeOnPlayerHit(nil, event.object2)
end
end
end
I just simplified the code for you
-- utility function
function isInArray(a, s, t)
local g = {}
for k, v in pairs(a) do
if t then
if v ~= s then
table.insert(g, v)
end
else
if v == s then
return true
end
end
end
return t and (#g > 0 and g or false) or false
end
-- this will hold all the enemies names
local enemies = {}
-- this function creates all the enemies
function createEnemies(name, number)
for i = 1, number do
table.insert(enemies, i, name..i)
end
end
-- now lets create the enemies, 4 enemies in total with the name enemy+n
-- e.g. enemy1, enemy2 etc.. for value of number
createEnemies('enemy', 4)
function onCollision(event)
local function removeOnPlayerHit(obj1, obj2)
-- see if either of the arguments are nil
local objects = isInArray({obj1, obj2}, nil, true)
-- now check if objects contains any of the objects
if next(objects) then
-- if it does cycle through them
for i = 1, #objects do
-- now check against all the enemies
if isInArray(enemies, objects[i].id) then
-- now remove the objects
display.remove(objecta[i])
end
end
end
end
local function showPlayerHit()
local tmr_onPlayerHit = timer.performWithDelay(1, playerHit, 1)
end
if event.phase == "began" then
if isInArray(enemies, event.object1.id) and event.object2.id == "character" then
showPlayerHit()
removeOnPlayerHit(event.object1, nil)
elseif isInArray(enemies, event.object2.id) and event.object1.id == "character" then
showPlayerHit()
removeOnPlayerHit(nil, event.object2)
end
end
end
The error is saying:
game.lua:171: attempt to index global 'playerBul' (a nil value)
Sorry if I put too much unnecessary code, I just do not know what is causing this error.
here are all the files for this game:
menu.lua:
local menu = {}
local bannermenu;
local selection;
menu.name = 'Menu'
local function play()
mode = require('game')
mode.load()
end
local options = {
{['text'] = 'Play', ['action'] = play},
{['text'] = 'Exit', ['action'] = love.event.quit}
}
function menu.load()
bannermenu = love.graphics.newImage(BANNER)
selection = 1
pointer = love.graphics.newImage(POINTER)
mode = menu
end
function menu.update()
return mode
end
function menu.draw()
love.graphics.draw(bannermenu, 200,10)
for i = 1,#options do
if i == selection then
love.graphics.draw(pointer, 300, 200 + i *20)
end
love.graphics.printf(options[i].text,0,200 + i * 20, love.graphics.getWidth(), 'center')
end
end
function menu.keypressed(key)
if key == "up" then
selection = (selection - 2)%(#options) + 1
elseif key == "down" then
selection = (selection) % (#options) + 1
elseif key == "return" then
options[selection].action()
elseif key == "escape" then
love.event.quit()
end
end
return menu
main.lua
TITLE = 'Die Aliens Die!'
PLAYER_BULLET = 'Images/playerbullet.png'
ENEMY_BULLET = 'Images/enemybullet.png'
HEALTH_IMG = 'Images/life.png'
ENEMY_UFO = {
ENEMY_1 = 'Images/enemy1.png',
ENEMY_2 = 'Images/enemy2.png',
ENEMY_3 = 'Images/enemy3.png'
}
PLAYER_IMG = 'Images/spaceship.png'
YOU_WIN = 'Images/win.png'
BANNER = 'Images/banner.png'
POINTER = 'Images/pointer.png'
function love.load()
love.window.setTitle(TITLE)
mode = require "menu"
mode.load()
end
function love.draw()
mode.draw()
end
function love.keypressed(key, isrepeat)
mode.keypressed(key)
end
function love.update(dt)
mode.update(dt)
end
game.lua
local game = {}
local playerShip = {}
local alienUFO = {}
local bullets = {}
local alienBullets = {}
local playerBullets = {}
local aliens = {{},{},{},{},{},{},{},{},{},{}}
local health = 3
local score = 0
local level = 1
local alienMovement = true
local healthImage;
local alienQty = 0
local pause
--local function gameOver()
--local function gamwWin()
local function clearTable(t)
for i = #t,1,-1 do
table.remove(t,i)
end
end
local function clearAliens()
for i=#aliens,1,-1 do
for j = #aliens[i],1,-1 do
table.remove(aliens[i],j)
end
end
end
local function insertAliens()
alienQty = 0
for i=1,4 do
for j =1,10 do
local alien = {}
alien.x = (j-1) *alienUFO.width + 10
alien.y = (j-1) *alienUFO.width + 35
if level ==2 then
alien.life = 2
if level == 3 then
alien.life = 3
end
table.insert(aliens[j], alien)
alienQty = alienQty + 1
end
end
end
end
local function initGame()
clearTable(playerBullets)
clearTable(alienBullets)
clearAliens()
insertAliens()
playerShip.x = love.graphics.getWidth() / 2 - playerShip.width /2
end
local function playerShoot()
local bullet = {}
playerShip.x = playerShip.x + 32
playerShip.y = playerShip.y + 10
table.insert(playerBullets, bullet)
end
local function AlienShoot(x,y)
local bullet = {}
bullet.x = alienUFO.width/2
bullet.y = y -5
table.insert(alienBullets, bullet)
end
local function playerShots(dt)
if next(playerBullets) ~= nil then
for i = #playerBullets,1,-1 do
playerBullets[i].y = playerBullets[i].y - dt* playerBullets.bulletSpeed
if playerBullets[i].y < 0 then
table.remove(playerBullets,i)
else
for j = #aliens, 1,-1 do
for k = #aliens[j],1,-1 do
if next(playerBullets) ~= nil and playerBullets[i] ~= nil and
aliens[j][k].x <= playerBullets[i].x and aliens[j] [k].x + 50 >= playerBullets[i].x
and aliens[j][k].y <= playerBullets[i].y and aliens[j] [k].y + 47 >= playerBullets[i].y then
table.remove(playerBullets, i)
if level == 2 and aliens[j][k].life > 0 then
aliens[j][k].life = aliens[j][k].life - 1
if level == 3 and aliens[j][k].life > 0 then
aliens[j][k].life = aliens[j][k].life - 1
else
table.remove(aliens[j], k)
alienQty = alienQty - 1
score = score + 100
end
break
end
end
end
end
end
end
end
local function PlayerShot()
health = health - 1
if health == 0 then
love.event.quit() -- COME BACK HERE FOR LOSE
end
end
local function AlienShots(dt)
if next(alienBullets) ~= nil then
for i = #alienBullets,1,-1 do
alienBullets[i].y = alienBullets[i].y + dt * alienUFO.bulletSpeed
if alienBullets[i].y > love.graphics.getHeight() then
table.remove(alienBullets, i)
elseif playerShip.x <= alienBullets[i].x and playerShip.x + playerShip.width >= alienBullets[i].x
and playerShip.y <= alienBullets[i].y and playerShip.y + playerShip.height >- alienBullets[i].y then
table.remove(alienBullets, i)
PlayerShot()
end
end
end
end
local function nextLVL()
level = level + 1
if level == 2 then
alienUFO.image = love.graphics.newImage(alienUFO.ENEMY1)
alienUFO.speed = 100
alienUFO.shotProb = 20
alienUFO.bullet = alienBul.image
initGame()
elseif level == 3 then
alienUFO.image = love.graphics.newImage(alienUFO.ENEMY2)
initGame()
elseif level > 3 then
love.event.quit() -- COME BACK HERE FOR WIN
end
end
function game.load()
pause = false
level = 1
health = 3
score = 0
playerShip.speed = 300
playerShip.bulletSpeed = 300
playerShip.width = 75
playerShip.height = 71
alienUFO.speed = 70
alienUFO.width = 50
alienUFO.height = 47
alienUFO.ENEMY1 = ENEMY_UFO.ENEMY_1
alienUFO.ENEMY2 = ENEMY_UFO.ENEMY_2
alienUFO.ENEMY3 = ENEMY_UFO.ENEMY_3
alienUFO.bulletSpeed = 300
alienUFO.image = love.graphics.newImage(alienUFO.ENEMY3)
playerShip.IMAGE = PLAYER_IMG
playerShip.image = love.graphics.newImage(playerShip.IMAGE)
healthImage = love.graphics.newImage(HEALTH_IMG)
playerShip.x = love.graphics.getWidth() / 2 - playerShip.width/2
playerShip.y = love.graphics.getHeight() - 100
playerBul.image = love.graphics.newImage(PLAYER_BULLET)
alienBul.image = love.graphics.newImage(ENEMY_BULLET)
initGame()
end
function game.draw()
if pause then
love.graphics.print('GAME PAUSED',love.graphics.getWidth()/2 - 20,20)
end
if next(playerBullets) ~= nil then
for i = 1, #playerBullets do
love.graphics.draw(playerBul.image, playerBullets[i].x, playerBullets[i].y)
end
end
if next(alienBullets) ~= nil then
for i = 1, #alienBullets do
love.graphics.draw(alienBul.image, alienBullets[i].x, alienBullets[i].y)
end
end
if next(aliens) ~= nil then
for i = 1, #aliens do
for j = 1, #aliens[i] do
love.graphics.draw(alienUFO.image, aliens[i][j].x, aliens[i][j].y)
end
end
end
love.graphics.print('Score: '..score, love.graphics.getWidth() - 100,20)
love.graphics.draw(playership.image, playership.x, playerShip.y)
for i = 1, lives do
love.graphics.draw(healthImage, 10+ 1 * 15,20)
end
end
function game.update(dt)
if not pause then
if alienQty == 0 then
nextLVL()
end
if love.keyboard.isDown("right") then
playerShip.x = playerShip.x + dt * playerShip.speed
elseif love.keyboard.isDown("left") then
playerShip.x = playerShip.x - dt * playerShip.speed
end
if love.keyboard.isDown(" ") then
playerShoot()
end
playerShots(dt)
AlienShots(dt)
if love.math.random(1,100) < alienUFO.shotProb then
local r = love.math.random(1,#aliens)
if next(aliens[r]) ~= nil then
alienShoot(aliens[r][#aliens[r]].x, aliens[r][#aliens[r]].y)
end
end
if alienMovement then
for i = 1, #aliens do
for j = 1, #aliens[i] do
aliens[i][j].x = aliens[i][j].x + dt * alienUFO.speed
if aliens[i][j].x + alienUFO.width + 2 >= love.graphics.getWidth() then
alienMovement = false
end
end
end
else
for i =1, #aliens do
for j = 1, #aliens[i] do
aliens[i][j].x = aliens[i][j].x - dt * alienUFO.speed
if aliens[i][j].x - 2 <= 0 then
alienMovement = true
end
end
end
end
if playerShip.x < 0 then
playerShip.x = 0
elseif playerShip.x > love.graphics.getWidth() - 75 then
playerShip.x = love.graphics.getWidth() -75
end
end
end
end
function game.keypressed(key)
if key =='p' then
pause = not pause
end
end
return game
you haven't defined a load function on the game table you return in game.lua. it looks like you already wrote the load logic but wrote it as a local function named loadGame. to fix your issue update game.lua to export the load function and just have it call the load function you've already created, like this:
function game.load()
loadGame()
end
somewhere before you return the game table in game.lua, say after your definition of game.keypressed
or you could alternatively just change local function loadGame() to function game.load() to remove the local function and redefine it as exported functionality