Coding Problems

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
User avatar
MicroMacro
Citizen
Posts: 92
Joined: Fri May 30, 2014 2:30 am
Location: Boston, MA, USA
Contact:

Coding Problems

Post by MicroMacro » Thu Jun 05, 2014 1:33 am

I'm relatively new to Lua, but this seems like it should work, but LOVE throws me an error at line 15.

Code: Select all

--Baddie Class
--All functions will be written as r + whatever the function is. R stands for RED
function rLoad()
	--rImgN = love.graphics.newImage("textures/rNeutral.png")
	rImgH = love.graphics.newImage("textures/rHostile.png")
	rspAm = math.random(17,25)
	rspX = math.random(0,love.window.getWidth()-32)
	rspY = math.random(0,love.window.getHeight()-32)
	counter = 0
end

function rSpawn()
	spawning = true
	while spawning == true do
		counter = counter + 1
		if counter > rspAm then
			break
		end
		love.graphics.draw(rImgH,r.spX,r.spY)
		rspX = math.random(0,love.window.getWidth()-32)
		rspY = math.random(0,love.window.getHeight()-32)
	end
end
Im trying to get it to repetitively spawn the blocks in random spots. Why isnt it working? Help is much appreciated.

Btw, the function is referenced in main.lua.
https://github.com/ebernerd- where you can find all my work.

User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Coding Problems

Post by substitute541 » Thu Jun 05, 2014 2:27 am

Did you call rSpawn before you called rLoad?

It's hard to find the problem without giving the error or the .love file to run.
Currently designing themes for WordPress.

Sometimes lurks around the forum.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Coding Problems

Post by Robin » Thu Jun 05, 2014 7:00 am

Yes, please upload the .love.

One thing I can see right now is that rSpawn doesn't work. It tries to draw something, but I assume rSpawn is not called inside love.draw, so it won't even be shown. If it were shown, depending on if you reset counter, these baddies will teleport all over the screen, creating a flickering mess.

You'll want to keep a table to store the baddie coordinates, fill it up in rSpawn and loop over the table to draw it in love.draw.
Help us help you: attach a .love.

User avatar
MicroMacro
Citizen
Posts: 92
Joined: Fri May 30, 2014 2:30 am
Location: Boston, MA, USA
Contact:

Re: Coding Problems

Post by MicroMacro » Thu Jun 05, 2014 7:54 pm

Thanks for the help. Here;s the love file.
My Love File.zip
Love file is in the ZIP
(10.7 KiB) Downloaded 33 times
https://github.com/ebernerd- where you can find all my work.

User avatar
DrCicero
Prole
Posts: 19
Joined: Sun Jun 01, 2014 8:56 pm
Location: Germany

Re: Coding Problems

Post by DrCicero » Thu Jun 05, 2014 8:14 pm

When Robin and substitute541 asked for a .love, they wanted one that produces the error, so they can help you. The love you just uploaded does not error, so i guess you solved your problem already? :huh:

If not you should also post the steps necessary to reproduce the error. :)
Xeldas Saga - my ca. 10min action-platformer (contains sound effects, music, graphics and a boss fight)

Post Reply

Who is online

Users browsing this forum: cazura and 3 guests