[CLOSED] Function disappearing [CLOSED]

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
seuterr
Prole
Posts: 5
Joined: Mon May 11, 2015 12:52 am

[CLOSED] Function disappearing [CLOSED]

Post by seuterr »

I've been working on my first game, and the code is very messy. However, I have separate files for different functions, and at the bottom of each file, I've been putting a larger function that holds all of the functions in that specific file. From there, I have

Code: Select all

require "collide"
in my main code. For each different type of function I have in those files, my super functions have a different category, such as

Code: Select all

COLLIDE_UPDATE()
to go into the love.update function. All of my other super functions like this are working perfectly, but when I try using my COLLIDE_UPDATE() function, when I load it up, it returns:

Error

main.lua:62: attempt to call global 'COLLIDE_UPDATE' (a nil value)


Traceback

main.lua:62: in function 'update'
[C]: in function 'xpcall'

When I take all of the individual functions and put them there without using the super function, it works.
For future reference after this point, gsize is what I multiply everything related to the coordinates, because my textures are 32x32, and I want them to be 64x64
collide.lua:

Code: Select all

function collidescreen(entity)
	--Keep entity on tiles
	if entity.x < 32 * gsize then
		bump:setVolume(.5)
		bump:play()
		entity.x = 32 * gsize
	end
	if entity.x > (288 * gsize) - 32 * gsize then
		bump:setVolume(.5)
		bump:play()
		entity.x = (288 * gsize) - 32 * gsize
	end
	if entity.y < 32 * gsize then
		bump:setVolume(.5)
		bump:play()
		entity.y = 32 * gsize
	end
	if entity.y > (288 * gsize) - 32 * gsize then
		bump:setVolume(.5)
		bump:play()
		entity.y = (288 * gsize) - 32 * gsize
	end
end
function collideconveyorbelt(entity)
	--Do entity conveyorbelt
	if entity.x > 64 * gsize and entity.x < 96 * gsize and entity.y > 64 * gsize and entity.y < 96 * gsize then
		entity.x = entity.x + 3.5
	end
end
function COLLIDE_UPDATE()
	collidescreen(player)
	collidescreen(zombie)
	collideconveyorbelt(player)
	collideconveyorbelt(zombie)
end
Yes, this is a very bad way to lay out code, and such, but I don't care about that right now.
love.update in main.lua:

Code: Select all

function love.update(dt)
	music:play()
	if gamestate ~= "paused" then
		--WASD Controls
		if love.keyboard.isDown("d") then								
			player.r = 90								
			player.x = player.x + player.speed * dt 	
		elseif love.keyboard.isDown("a") then											
			player.r = 270								
			player.x = player.x - player.speed * dt 	
		elseif love.keyboard.isDown("s") then	
			player.r = 180								
			player.y = player.y + player.speed * dt 	
		elseif love.keyboard.isDown("w") then							
			player.r = 0								
			player.y = player.y - player.speed * dt 	
		end
		--Entity movement
		zombie.loop = zombie.loop + zombie.inc * dt
		if zombie.loop > 0 and zombie.loop <= 7 then
			zombie.r = 0
			zombie.y = zombie.y - zombie.speed * dt
		elseif zombie.loop > 7 and zombie.loop <= 14 then
			zombie.r = 180
			zombie.y = zombie.y + zombie.speed * dt
		elseif zombie.loop > 14 then 
			zombie.loop = 1
		end
	end
	--Collision updates
	COLLIDE_UPDATE()
end
The entities I'm using (in entities.lua):

Code: Select all

--Player entity statuses
player = {
	x = 48 * gsize,
	y = 48 * gsize,
	speed = 125,
	r = 0
}
--Zombie entity statuses
zombie = {
	x = 240 * gsize,
	y = 272 * gsize,
	speed = 80,
	r = 0,
	loop = 1,
	inc = 1
}
--Girl NPC entity statuses
girl = {
	x = 80 * gsize,
	y = 40 * gsize,
	r = 180
}
If you need more information to help me get this fixed, I can post all of the code for my game. Until then, if you can help me, please do.
Last edited by seuterr on Thu May 21, 2015 11:29 pm, edited 1 time in total.
Hey there... Wanna buy some wow?
User avatar
BOT-Brad
Citizen
Posts: 87
Joined: Tue Dec 02, 2014 2:17 pm
Location: England

Re: Function disappearing

Post by BOT-Brad »

If you could attach your .love file or simply a .zip or .rar of your code, that would help find the issue much easier. :nyu:
Follow me on GitHub! | Send me a friend request on PSN!
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Function disappearing

Post by s-ol »

You probably just forgot to "require" the file that defines it.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
seuterr
Prole
Posts: 5
Joined: Mon May 11, 2015 12:52 am

Re: Function disappearing

Post by seuterr »

S0III0s: I will put up the code later today, but as of the moment I actually do have the require for the said file, and like I said, it works when I don't use the super function, but when I do, it fails and generates the error.
Hey there... Wanna buy some wow?
User avatar
seuterr
Prole
Posts: 5
Joined: Mon May 11, 2015 12:52 am

Re: Function disappearing

Post by seuterr »

Here is the download link for the zip file containing everything required to run the game. https://www.mediafire.com/?g7gs3dmssnf9uaz
Hey there... Wanna buy some wow?
User avatar
BOT-Brad
Citizen
Posts: 87
Joined: Tue Dec 02, 2014 2:17 pm
Location: England

Re: Function disappearing

Post by BOT-Brad »

Just from looking at the code, there is no COLLIDE_UPDATE function in your collide.lua file. If I add in

Code: Select all

function COLLIDE_UPDATE()
   collidescreen(player)
   collidescreen(zombie)
   collideconveyorbelt(player)
   collideconveyorbelt(zombie)
end
under your MAP_UPDATE function, then the game runs and works as I expect it should.
Follow me on GitHub! | Send me a friend request on PSN!
User avatar
seuterr
Prole
Posts: 5
Joined: Mon May 11, 2015 12:52 am

Re: Function disappearing

Post by seuterr »

BOT-Brad wrote:Just from looking at the code, there is no COLLIDE_UPDATE function in your collide.lua file. If I add in

Code: Select all

function COLLIDE_UPDATE()
   collidescreen(player)
   collidescreen(zombie)
   collideconveyorbelt(player)
   collideconveyorbelt(zombie)
end
under your MAP_UPDATE function, then the game runs and works as I expect it should.
For some reason, I uploaded the wrong file. When I run what you have, the game works fine, but with my current version, the map is not stored in the collide.lua file. I'm probably just being really dumb, but I replaced the file with the new one.
Hey there... Wanna buy some wow?
User avatar
seuterr
Prole
Posts: 5
Joined: Mon May 11, 2015 12:52 am

Re: Function disappearing

Post by seuterr »

Yup. I was just being stupid. Thank you for all of the help!
Hey there... Wanna buy some wow?
Post Reply

Who is online

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