Page 1 of 2

String expected Got nil

Posted: Tue Apr 05, 2011 2:16 pm
by Evrim

Code: Select all

function love.load()

	timert = 4.0
	statet = 0
	story = "none"
	
end

function love.draw()

	love.graphics.printf(story, 48, 144, 500, 'center')
	
end
story is a string, but it gives an error of being nil

Re: String expected Got nil

Posted: Tue Apr 05, 2011 2:30 pm
by vrld
Works on my end... Maybe you have a typo somewhere?
You can find these kinds of errors with a strict-module, like strict.lua.

Re: String expected Got nil

Posted: Tue Apr 05, 2011 2:35 pm
by Evrim
the problem is not because of printf as if I add ' ' or " " to the ends of story, it just accepts it

but I need that for a timer that replaces the variable story


also is there a way that I can store all my variables in another lua file to keep love.load tidy?

EDIT: Ran the code, "variable story not declared"?

Re: String expected Got nil

Posted: Tue Apr 05, 2011 2:48 pm
by Robin
Could you give a .love of your code, please? Because this fragment just works.

Re: String expected Got nil

Posted: Tue Apr 05, 2011 2:55 pm
by Evrim
Loads of code commented in case I forget what I wrote

Also I need help with using vars.lua, can I use variables from there to main or other scripts?


EDIT: Image in your signature is pretty scary

Re: String expected Got nil

Posted: Tue Apr 05, 2011 2:59 pm
by vrld
  1. It would have been nice if you gave an example on how to reach the error ('press s' would have sufficed)
  2. love.load() will not call itself after you require story.lua, so you have to do it.
  3. That is not a good way of handling gamestates.

Re: String expected Got nil

Posted: Tue Apr 05, 2011 3:05 pm
by Evrim
How am I supposed to call it

love.load() at the line 1?


and if you mean "state" or "statet", they are just here because I'm new to Lua and general coding (would you suggest better ways to handle my variables and so?)

Re: String expected Got nil

Posted: Tue Apr 05, 2011 3:14 pm
by Robin
You shouldn't redefine callbacks (not in this way at least). I suggested in another thread how to deal with this:

Make a table called states.
Put require "story" at the top of your main.lua file.
Put the code for the menu in another file and require that.

Code: Select all

states = {}
require("story")
require("menu")

function love.load()
Do this in love.draw:

Code: Select all

states[state].draw()
Do the save for love.update and love.keypressed.

Change story.lua and menu.lua so that they do not override the love callbacks, but call them states.story.update and states.menu.update and so on.

Re: String expected Got nil

Posted: Tue Apr 05, 2011 6:08 pm
by Evrim
Tried a font, first it ran correctly without problems

But I added fontbig ( 32pt one, same font ) and now code does not recognises it?

Re: String expected Got nil

Posted: Tue Apr 05, 2011 6:36 pm
by Robin
I don't see a bigfont anywhere?

Plus, the file is named "font.TTF", not "font.ttf". That matters.

Plus, you misunderstood a couple of things about game state. I'd explain it more clearly, but I don't know how. Tell me, how much experience do you have with Lua?