String expected Got nil

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Evrim
Prole
Posts: 20
Joined: Fri Apr 01, 2011 4:22 pm

String expected Got nil

Post 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
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: String expected Got nil

Post 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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Evrim
Prole
Posts: 20
Joined: Fri Apr 01, 2011 4:22 pm

Re: String expected Got nil

Post 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"?
Last edited by Evrim on Tue Apr 05, 2011 2:50 pm, edited 1 time in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: String expected Got nil

Post by Robin »

Could you give a .love of your code, please? Because this fragment just works.
Help us help you: attach a .love.
Evrim
Prole
Posts: 20
Joined: Fri Apr 01, 2011 4:22 pm

Re: String expected Got nil

Post 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
Attachments
Taverno.love
(28.76 KiB) Downloaded 98 times
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: String expected Got nil

Post 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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Evrim
Prole
Posts: 20
Joined: Fri Apr 01, 2011 4:22 pm

Re: String expected Got nil

Post 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?)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: String expected Got nil

Post 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.
Help us help you: attach a .love.
Evrim
Prole
Posts: 20
Joined: Fri Apr 01, 2011 4:22 pm

Re: String expected Got nil

Post 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?
Attachments
Innsront.love
(34.24 KiB) Downloaded 99 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: String expected Got nil

Post 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?
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests