Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Recommended Posts

Hey guys.

I need help on this one. I am trying to create a script for storage containers in my game. 

So far I can walk up to the container, Press Use and it launches a GUI.

But for some reason I can't get the button to work. I can click on the button. But it doesn't process button events. To print the command to the system. I will paste my code below.

test1 = 0
function Storage() 
	local Storage={}
	local scale = 1
	
	--GUI
	gui = GUI:Create(context)
	
	gui:SetScale(scale)
	local widget
	Storage.gui=gui
	Storage.context = context
	gui:GetBase():SetScript("Scripts/GUI/Panel.lua")
	Storage.but1 = Widget:Button("Testing",10,20,80,30,gui:GetBase())
	gui:Hide()

function Storage:Update()

	self:ProcessEvent(Event(Event.WidgetAction))
	while EventQueue:Peek() do
			local event = EventQueue:Wait()
			if self:ProcessEvent(event)==false then return false end
		end
		return true
end

function Storage:ProcessEvent(event)

				
		if event.id == Event.WidgetSelect then
			

			
		elseif event.id == Event.WidgetAction then
			

		if event.source == self.but1 then

		System:Print("Button Working")



		end
	
end

return true

	
end
return Storage
end

function Script:Start()
Storage()
end


function Script:Use()
test1 = 1
gui:Show()
Time:Pause()
mlook = 1
context:GetWindow():ShowMouse()
end

 

Link to post
Share on other sites
On 10/6/2018 at 12:26 AM, slimwaffle said:

if event.source == self.but1 then

replace that line with this 

if event.source == Storage.but1 then

Your Storage variable was created as a global variable. It is not local to the script that created it.

Link to post
Share on other sites
17 minutes ago, Einlander said:

replace that line with this 


if event.source == Storage.but1 then

Your Storage variable was created as a global variable. It is not local to the script that created it.

I did this but the button still isn't printing to the system.

Link to post
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.

×
×
  • Create New...