Jump to content

[Solved] Problem with Show/Hide Child in vwep Praefab


burgelkat
 Share

Recommended Posts

Hallo,

i hope someone can explain this to me.

i build a vwep praefab (like autogun)

this script function and the bucket is show

 

in the Start function i have this code.

if i take the bucket, the child is now hidden.

function Script:Start()

	local child = self.entity:FindChild("WaterforBucket")	
	child:Hide()

 

the problem now is, if i would show it again, i got an error.

this is the code for showing the child

function Script:becomewater()--in
	self.becomewater=true
	local child = self.entity:FindChild("WaterforBucket")	
		if child:Hidden() then
			child:Show()
		end
end

the child is now nil. (Script Error attempt to index local "child" (a nil value)

why now the child is not found?

can someone explain and how i can fix it?

bucket.jpg

Link to comment
Share on other sites

Since you can find the child on Start, I would store it in a variable to quick and easy access. I'd also put in null checks.

Script.vmodel = nil
function Script:Start()

	local child = self.entity:FindChild("WaterforBucket")	
  	if child ~= nil then 
    	self.vmodel = child 
    	self.vvmodel:Hide()
  	end
 end

function Script:DoSomething()
  	-- Get my view model!
  	local vm = self.vmodel
  	vm:SetColor(1,0,0,1)
end

 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

  • burgelkat changed the title to [Solved] Problem with Show/Hide Child in vwep Praefab
Quote

the problem now is, if i would show it again, i got an error.

this is the code for showing the child


function Script:becomewater()--in
	self.becomewater=true
	local child = self.entity:FindChild("WaterforBucket")	
		if child:Hidden() then
			child:Show()
		end
end

the child is now nil. (Script Error attempt to index local "child" (a nil value)

why now the child is not found?

This is still a good question...

Maybe it depends on where do you call the becomewater() function from 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...