Page 1 of 1

problem with code here

Posted: 26 Mar 2016, 07:33
by RPGMAN34
I have been having troubles with some of my code for this game (you will have to find out in the code if you want spoilers)
function love.load()
mouse = {
x = love.mouse.getX(),
y = love.mouse.getY(),
showtext = ""
}

window = {
width = 1250,
height = 750
}

font = {
medium = love.graphics.newFont(20),
big = love.graphics.newFont(45)
}

stats = {}

require "images" --Images have all the files for photos
require "audio" --Like images but for soulds and music
require "cookie"
require "achievement" --Why not have Achievements?!?
require "milestone" --Cant forget Milestones!!! :)
end

function love.update(dt)
mouse.x = love.mouse.getX()
mouse.y = love.mouse.getY()

cookie.cpsCollect()
end

function love.mousepressed(x, y, button, istouch)
if button == 1 then
cookie.collect()
end
end

function stats.save()
if not love.filesystem.isFile("save.txt") then
love.filesystem.newFile("save.txt")
end
end

function love.draw()
--This area is the background
love.graphics.draw(image.background.blue)
love.graphics.draw(image.background.blue, 600, 0)
love.graphics.draw(image.background.blue, 0, 600)
love.graphics.draw(image.background.blue, 600, 600)
love.graphics.draw(image.background.blue, 1200, 0)
love.graphics.draw(image.background.blue, 1200, 600)
--Finnished with the blue stuff! :D

love.graphics.setColor(0, 0, 0, 100)
love.graphics.rectangle("fill", window.width / 3 * 2 + 80, 0, window.width / 3, window.height + 100)
love.graphics.reset()

love.graphics.draw(image.separator.horizontal, window.width / 3, 100)
love.graphics.draw(image.separator.vertical, window.width / 3, 512)
love.graphics.draw(image.separator.vertical, window.width / 3, 0)
love.graphics.draw(image.separator.vertical, window.width / 3 * 2 + 80, 0)
love.graphics.draw(image.separator.vertical, window.width / 3 * 2 + 80, 512)
--End Of Background

love.graphics.setColor(0, 0, 0, 100)
love.graphics.rectangle("fill", 0, 100, window.width / 3, 100)
love.graphics.reset()

love.graphics.setFont(font.big)
love.graphics.printf(cookie.money, 0, 125, window.width / 3, "center")

love.graphics.setFont(font.medium)
love.graphics.printf(active, window.width / 3 + 115, 10, 300, "center")

love.graphics.draw(cookie.image, cookie.x, cookie.y) --Clicking this image gives you a cookie

love.graphics.setFont(font.medium)
love.graphics.print(mouse.showtext, mouse.x, mouse.y - 10)

stats.save()
end it looks a lot different in the actual code.

and when I run the code, I get this...
Error

main.lua:56: attempt to index global 'stats' (a nil value)


Traceback

mai.lua: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'
anyway you can help? sorry if this is in the wrong forum...

Re: problem with code here

Posted: 08 Apr 2016, 16:12
by HugoBDesigner
First: yes, this is the wrong forum, as this is dedicated to Stabyourself.net games (EDIT: thread was moved to proper subforum). For general technical support with your projects, I encourage you to try out the Love2D Forums

Second: because of your highly-modified code, we can't determine what causes the error. As you can see, the error reports that the variable "stats" on line 56 doesn't exist, but in your modified code, line 56 doesn't even mention that variable.

Sorry, we can't help you much currently...