Errors in code

so I know why my code is throwing these errors and I know what it is throwing but I don’t know to fix it, like i understand It’s calculating with a nil value that doesn’t have a value but i try to populate it and then I’m thinking my table is set up wrong maybe

 local text_nodes = {"score","health1","health2","health3","health4","health5","wave","gameover","endscore",}
local box_nodes = {"playagain"}
local health = 5
function init(self)
	self.score = 0  
	self.endscore = 0                                        
	self.health = 5
end
function on_message(self, message_id, message, sender)
	if message_id == hash("add_score") then                 
		self.score = self.score + message.score             
		local scorenode = gui.get_node("score")             
		gui.set_text(scorenode, "SCORE: " .. self.score)    
**--elseif message_id == hash("take_damage") then**
**		**self.health = self.health-message.damage**
		**--node =gui.get_node("health".. healths)**
**		**--gui.set_color(node, vmath.vector4(1, 1, 1, 1))****
**		--gui.animate(node, gui.PROP_COLOR, vmath.vector4(1,1,1,0), gui.EASING_OUTCIRC, 1.0)**
**--elseif message_id== hash("healing") then **
**		--self.health = self.health+message.health**
**		--node=gui.get_node("health"..healths)**
**		--gui.set_color("health", 0,0,0,1)**
**		--gui.animate(node, gui.PROP_COLOR, vmath.vector4(1,1,1,1), gui.EASING_OUTCIRC, 1.0)**
elseif message_id == hash("gameover") then 
show_game_over(self)
		msg.post("controller:/controller","show_menu")
	end
end
go.property("health", 5)
local COLLISION_RESPONSE= hash("collision_response")
local DAMGA = hash("damage")
local TANK = hash("tanks")
local MEDIC = hash("medic")
local ENEMY= hash ("enemy")
local HELICOPTER=hash("helicopter")
local POWERUP=hash("powerup")

– t is the table

function init(self)                                 
	msg.post("#", "acquire_input_focus")            

	self.moving = false
	self.firing = false                             
	self.input = vmath.vector3()                    
	self.dir = vmath.vector3(0, 1, 0)             
	self.speed = 50                                 
	self.health=5


end

function final(self)                                
	msg.post("#", "release_input_focus")            
end
function on_message(self, message_id, message, sender)
	**if message_id ==COLLISION_RESPONSE and message.group ==TANK then**
**		--self.health=self.health-message.damage**
**		msg.post("/gui#ui", "take_damage", {damage = 1})**
**		--self.health=health-message.damage**
		print("hurt", sender)
	elseif message_id ==COLLISION_RESPONSE and message.group ==ENEMY then
		--self.health=self.health-message.damage
		--go.delete()
		print("hurt", sender)
	elseif message_id ==COLLISION_RESPONSE and message.group ==HELICOPTER then
		--self.health=self.health-message.damage
		print("hurt", sender)
	elseif message_id ==hash("healing")then
		msg.post("/gui#ui", "healing", {healing = 1})
		self.health = self.health + message.healing
		print("healing", sender)
	elseif message_id ==COLLISION_RESPONSE and message.group ==POWERUP then
		print("powerup", sender)
		end
	end
	**if message_id ==hash("damage") then**
**		self.health=self.health-message.damage**
**		print("hurt",sender)**
**	msg.post("/gui#ui", "take_damage", {damage = 1})**
end

and this is the message that my take sends for damage to the player
if message_id==hash(“collision_response”) and message.group == PLAYER then
msg.post(“player#player”, “damage”,{1})
print(“damage”,sender)
end

the error occurs in the elseif function with take_damage “self.health=health-message.damage” as well as the healing witch is just “self.health=health+message.healing”(they have been made bold to see better, I’m just stuck and it prints out damage and he’s hurt but I can’t get the health to ever go <= 0 to delete.go i’ve created a go.property did local self.health=5 I have my health nodes in a table with the gui text nodes If anybody can help would be cool, I can also update my gist on github with the curret full code if that helps its been through several iterations also my proxies don’t unload and load like the first one loads and prints it succesfully loaded and i checked to make sure everything is named right the title or the game both load but they won’t load the other once one is loaded the title gui script has an error sending the message show_game to the controller script

It is fairly hard to read through what is going on here. It would probably be better if you just attached the project as a zip file. You have also included lots of code that you commented out (using --), but I am not certain whether you want them to be included in the script or not, as some of them seem to be quite important.

One potential error I can see is that you both have a local variable called ‘health’ as well as a variable in self, called ‘self.health’. What is the difference between these two? Do you need both? For example, you use both of them in this part of the code:

self.health=self.health-message.damage
msg.post("/gui#ui", “take_damage”, {damage = 1})
self.health=health-message.damage
1 Like

so the commented out part is what isn’t working in my code, also i was trying both ways to manipulate health so there may be 2 functions that both do the same thing I just was experimenting and commenting out stuff to run the code and make it work let me get the zip for you to look at

i think this is the correct file

i’m trying to upload the zip and I can’t see it? like i click upload file then select it and then it doesn’t post or show up in the text box after i try uploading it

We probably don’t support zip files on the forum. It’s better if you put the zip on Google Drive, Dropbox or similar and share the link here.

cool beans man, here it is https://drive.google.com/file/d/1uKNPreGpC5xTf89YIMjKeiUF3ZgHGsIM/view?usp=sharing

also, It may be confusing I am working on cleaning it up and proper coding procedure. so i’m sorry in advance don’t burn me at the cross please I will take any and all suggestions to fix it

Ok, so I changed your controller.script to load the title collection first. When I click the play button you do this:

msg.post("controller:/controller", "show_game")

Which results in:

ERROR:SCRIPT: /main/scripts/title.gui_script:12: Could not send message 'show_game' from 'title:/title#title' to 'controller:/controller'.

The thing is that you have no collection with id controller. The main.collection has an id of main (select the root of the collection and check the properties panel). What you need to do is to change to post this message:

 msg.post("main:/controller", "show_game")

We do support zip uploads on the forum:

Screen Shot 2018-05-25 at 10.03.41.zip (171.7 KB)

2 Likes

oh man thanks so much!!! and yeah i’ve uploaded a zip before, I don’t know what that is about. y’all help out so much thanks again guys literally y’all are like an influence and inspiration, not all heroes wear capes

2 Likes

Maybe we have a size limit @sicher? The zip that was shared with me was 70Mb or something like that.

Yes, the limit is set to about 50MB.

1 Like