Jump to content

[ SOLVED ] Missing 'end'


Recommended Posts

Not sure if this is the correct place for this; however, I am making a bit of a schoolboy error and after numerous attempts to rectify it myself I am having a bit of trouble. There is a missing end function that resolves the if.GLOBAL line. I got the character to plant rabbit holes and then added in those extra two lines to make this ability unique to her. Can anyone help me out with where the missing end goes?

local function rabbitHolePostInit(inst)
    if GLOBAL.GetPlayer().prefab == "bob" then
 
local function CanDeploy(inst) return true end
local function ondeploy(inst, pt)
 local rabbit = GLOBAL.SpawnPrefab("rabbithole")
 if rabbit then
  rabbit.Transform:SetPosition(pt.x, pt.y, pt.z)
 end
end

function rabbitHole(inst)
    inst:AddComponent("deployable")
 inst.components.deployable.test = function() return true end
 inst.components.deployable.ondeploy = ondeploy
 
end

AddPrefabPostInit("rabbit", rabbitHole)
 
I feel so silly for not being able to work this one out myself. I am slowly improving my coding abilities but in, well, very tentative baby steps. 
 
Link to comment
Share on other sites

21 minutes ago, Aquafox333 said:

local function rabbitHolePostInit(inst)

    if GLOBAL.GetPlayer().prefab == "bob" then
 
local function CanDeploy(inst) return true end
local function ondeploy(inst, pt)
 local rabbit = GLOBAL.SpawnPrefab("rabbithole")
 if rabbit then
  rabbit.Transform:SetPosition(pt.x, pt.y, pt.z)
 end
end

function rabbitHole(inst)
    inst:AddComponent("deployable")
 inst.components.deployable.test = function() return true end
 inst.components.deployable.ondeploy = ondeploy
 
end

AddPrefabPostInit("rabbit", rabbitHole)
 

Hey, indentation might be something to look into, it makes your code neater.
 

local function rabbitHolePostInit(inst)
   if GLOBAL.GetPlayer().prefab == "bob" then

		local function CanDeploy(inst) return true end
		local function ondeploy(inst, pt)
 		local rabbit = GLOBAL.SpawnPrefab("rabbithole")
   end
      
 	if rabbit then
  		rabbit.Transform:SetPosition(pt.x, pt.y, pt.z)
  	end

end

function rabbitHole(inst)
    inst:AddComponent("deployable")
 	inst.components.deployable.test = function() return true end
 	inst.components.deployable.ondeploy = ondeploy
end

AddPrefabPostInit("rabbit", rabbitHole)

I'm not entirely sure if that's what you want, give it a spin and tell me if it works as intended

Link to comment
Share on other sites

@ImDaMisterL

Ah, collaboration. I assumed it was a request for help, period. Thank you for sorting that.

 

@ThemInspectorsimage.thumb.png.34831e2039bff6f813eb9e1d3a4b1c0f.png

Thank you for your assistance. Indentation is definitely a weak point of mine. I am actually going to polish it at the weekend if time allows.

10 hours ago, ThemInspectors said:

local function rabbitHolePostInit(inst) if GLOBAL.GetPlayer().prefab == "bob" then local function CanDeploy(inst) return true end local function ondeploy(inst, pt) local rabbit = GLOBAL.SpawnPrefab("rabbithole") end if rabbit then rabbit.Transform:SetPosition(pt.x, pt.y, pt.z) end end function rabbitHole(inst) inst:AddComponent("deployable") inst.components.deployable.test = function() return true end inst.components.deployable.ondeploy = ondeploy end AddPrefabPostInit("rabbit", rabbitHole)

So, the game crashed and offered me this helpful titbit. Problem is, this is how I came to learn I was missing an end in the first place. Any more suggestions? I'm greatly appreciative of your help. Also, if you do know how to fix this, could you tell me what the issue is, and how you solved it, so I don't need to ask anyone for help should this problem arise in the future?

Link to comment
Share on other sites

@Aquafox333

Sorry, I made an error in my code, so sorry that I missed it, it should be this
 

local function rabbitHolePostInit(inst)
   if GLOBAL.GetPlayer().prefab == "bob" then
		local function CanDeploy(inst) return true end
		local function ondeploy(inst, pt) end
 		local rabbit = GLOBAL.SpawnPrefab("rabbithole")
   end

 	if rabbit then
  		rabbit.Transform:SetPosition(pt.x, pt.y, pt.z)
  	end

end

function rabbitHole(inst)
    inst:AddComponent("deployable")
 	inst.components.deployable.test = function() return true end
 	inst.components.deployable.ondeploy = ondeploy
end

AddPrefabPostInit("rabbit", rabbitHole)

it was on the

local function ondeploy(inst, pt) end

there was a missing end there.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...