confused about print() statements

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.
Post Reply
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

confused about print() statements

Post by randy0428 »

I'm VERY confused.

In main.lua I have function love.draw(), the first line of which is:
print("Game has started.").
This is followed by a love.graphics.draw statement that draws the background image.

After this there is a series of if statements to call a draw function depending on the game state, one of which is “splash”.

In the splash.lua file there is a draw function which draws the screen for this scene. It essentially works fine. When the game state is splash, the game draws everything in the splash draw function. The problem is that the above mentioned print statement (print("Game has started.")) doesn’t print in the console as expected, since it is in the love.draw() function BEFORE any of the if statments. Additionally, at the beginning of the main.lua file, immediately after defining gameState = "splash", there is a print statement, print("gameState = " , gameState), which also DOESN’T print in the console.

The funny thing is, when these print statement weren’t printing, in my attempts to figure out why, I added a print statement, print("in stateSplash.draw()"), to the stateSplash.draw() function in the splash.lua file. With this statement in place ALL of the print statements printed: this statement, the one at the beginning of main and the one in the if block in love.draw().

I commented out the print statment in stateSplash.draw() and again, NONE of the print statements printed. I don’t understand this behavior.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: confused about print() statements

Post by zorg »

Me neither, which can mean two things.
1. Less likely: Löve (or something that it uses internally) has a bug somewhere;
2. More likely: Your code (or a lib you might be using) has a bug somewhere.

While the information's amount that you have written to describe the symptoms and stuff is a lot, i don't think we (or at least i) can go on just that amount of info, since it doesn't contain too much meaningful things; for example:
- How the processing flow goes between functions, files, etc.
- Whether this isn't just an issue of the console not being enabled (shouldn't be since it did print for you at one point)
- Whether or not you're re-defining print somewhere
etc.

I think you should attach the .love file for us to check out.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: confused about print() statements

Post by erasio »

I know that some consoles don't update in real time but simply stack up prints and display them at a later time (in my case this was usually after the game closed).

The solution was to add this at the top of the main.lua:

Code: Select all

io.stdout:setvbuf("no")
Which explicitly states to not buffer but to display live instead.

Maybe it solves your problem too.
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

SOLVED: confused about print() statements

Post by randy0428 »

Thanks zorg and erasio.

Erasio, your solution worked for me. I added "io.stdout:setvbuf("no")" at the beginning of main.lua and commented out the print statement that was "allowing" the other print statements to print and the other print statments printed. I then commented out "io.stdout:setvbuf("no")" and again, they didn't print.

So that solved the problem. I'll keep "io.stdout:setvbuf("no")" there so I don't have a problem in the future.

Thanks again.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 48 guests