How to address GO

I have several GO spawn…and when two of the same objects collide I have them deleting, but I can’t figure out why I can’t spawn new objects based on the previous object deletion. My issue appears that I can’t get my else if statement working properly. I can spawn a new object, but I want to do it based on what object was just deleted. So if an onion is deleted it spawns a red onion…if a red onion is deleted it spawns a radish. and if a radish is deleted it spawns a carrot.

When I print the object for my if statement it gives me one of the following:

DEBUG:SCRIPT: hash: [radish]
DEBUG:SCRIPT: hash: [onion]
DEBUG:SCRIPT: hash: [redonion]

but how do I test for that in my if statement? I’ve tried nearly everything I can think of. My issue appears to be in the If statement…I can’t test if that is true or not…everything comes back false so it ignores my if statement.

my currently else statemetn

function spawnnewVeggie(group, pos) 
	print(group)
	--factory.create("main:/factories#carrotfactory")   
	if group == "#radish" then
		factory.create("main:/factories#redonionfactory")
	elseif group == "hash: [radish]" then
		factory.create("main:/factories#raddishfactory")
	elseif group == "hash: [radish]" then
		factory.create("main:/factories#carrotfactory")
	end
end

Have you tried:

if group == hash("radish") then
2 Likes

Here’s how I solved it. Now to post on the next issue :slight_smile:

    function spawnnewVeggie(group, pos)
    	local sGroup = tostring(group)
    	if string.find(sGroup, "radish") then
    		factory.create("main:/factories#carrotfactory", pos)
    	elseif string.find(sGroup, "redOnion") then
    		factory.create("main:/factories#carrotfactory", pos)
    	elseif string.find(sGroup, "xnion") then
    		factory.create("main:/factories#carrotfactory", pos)
    	end	
    end

Are you converting the hash to a string? That will not work in release builds (try it). Did you try my suggestion?

4 Likes

Thank you. I just tried it and your solution works great. Thank you.

Check out my post about ChatGPT telling me to come here…it’s my new issue :frowning: