Jump to content

HELP : في tables & onClientGUIClick


Recommended Posts

سلام عليكم

شباب انا جربت اسوي شيء بس ماظبط معاي ومافية اخطاء بالدي بوق

local Functions = { 
[1] = { Button = join , Function = joinJob },
[2] = { Button = ex , Function = closeWindow },
[3] = { Button = leave , Function = leaveJob },
[4] = { Button = ex_1 , Function = closeWindow1 },
}


addEventHandler("onClientGUIClick",resourceRoot,function()
for index = 1 , #Functions do 
if ( source == Functions [ index ] [ "Button" ] ) then 
Functions [ index ] [ "Function" ] ()
end
end
end
)

 

Link to comment
50 minutes ago, #kAsR said:

سلام عليكم

شباب انا جربت اسوي شيء بس ماظبط معاي ومافية اخطاء بالدي بوق


local Functions = { 
[1] = { Button = join , Function = joinJob },
[2] = { Button = ex , Function = closeWindow },
[3] = { Button = leave , Function = leaveJob },
[4] = { Button = ex_1 , Function = closeWindow1 },
}


addEventHandler("onClientGUIClick",resourceRoot,function()
for index = 1 , #Functions do 
if ( source == Functions [ index ] [ "Button" ] ) then 
Functions [ index ] [ "Function" ] ()
end
end
end
)

 

انت معرف الفنكشنات ذي اصلا؟

Link to comment
function Button1 ( )
	outputChatBox ("1")
end
function Button2 ( )
	outputChatBox ("2")
end
function Button3 ( )
	outputChatBox ("3")
end
function Button4 ( )
	outputChatBox ("4")
end

Buttons = { }
 
Buttons[1] = guiCreateButton(50,50,20,20,"1",false)
Buttons[2] = guiCreateButton(50,70,20,20,"2",false)
Buttons[3] = guiCreateButton(50,80,20,20,"3",false)
Buttons[4] = guiCreateButton(50,95,20,20,"4",false)

Functions = { 
	[1] = { Function = Button1 },
	[2] = { Function = Button2 },
	[3] = { Function = Button3 },
	[4] = { Function = Button4 }
}

addEventHandler ( "onClientGUIClick",root,
	function ( ) 
		for i = 1,#Functions do
			if source == Buttons[i] then
				Functions[i].Function( )
			end
		end
	end 
)

^ هذا مثال بسيط سويته لك جربه
 

Edited by iMr.WiFi..!
Link to comment
6 minutes ago, #kAsR said:

ايه معرفها

 Functions = { 
[1] = { Button = join , myfun = joinJob },
[2] = { Button = ex , myfun = closeWindow },
[3] = { Button = leave , myfun = leaveJob },
[4] = { Button = ex_1 , myfun = closeWindow1 },
}


addEventHandler("onClientGUIClick",resourceRoot,function()
for index,v in pairs(Functions) do 
if ( source == Functions [ index ] [ "Button" ] ) then 
Functions [ index ] [ "myfun" ] ()
  break
end
end
end
)

جرب

Edited by Master_MTA
Link to comment
Just now, #kAsR said:

@Master_MTA نفس الشيء ماظبط

Functions = { 
 {  join , joinJob },
 {  ex ,  closeWindow },
 {  leave , leaveJob },
 { ex_1 , closeWindow1 },
}


addEventHandler("onClientGUIClick",resourceRoot,function()
for index,v in ipairs(Functions) do 
if ( source == Functions [ index ] [1 ] ) then 
Functions [ index ] [ 2 ] ()
  break
end
end
end
)

جرب

Link to comment
join = guiCreateButton(50,50,20,20,"1",false)
ex = guiCreateButton(50,80,20,20,"2",false)
leave = guiCreateButton(50,90,20,20,"3",false)
ex_1 = guiCreateButton(50,105,20,20,"4",false)

function joinJob ( )
	outputChatBox ("join")
end
function closeWindow ( )
	outputChatBox ("ex")
end
function leaveJob ( )
	outputChatBox ("leave")
end
function closeWindow1 ( )
	outputChatBox ("ex_1")
end


local Functions = { 
{ Button = join , Function = joinJob },
{ Button = ex , Function = closeWindow },
{ Button = leave , Function = leaveJob },
{ Button = ex_1 , Function = closeWindow1 }
}



addEventHandler("onClientGUIClick",resourceRoot,
	function()
		for i,v in ipairs (Functions) do 
			if ( source == v[ "Button" ] ) then 
			v[ "Function" ] ( )
			end
		end
	end
)

^ جرب ذا + هذا مثال فقط عشان تفهم الفكرة

Edited by iMr.WiFi..!
Link to comment
3 minutes ago, #kAsR said:

فكرتي اني مسوي جدول فيه اسماء الازرار

وكمان فيه اسم الوظيفة يعني لو ظغط زر بالجدول تتفعل الوظيفة حقت الزر

حبيب قلبي مستحيل ما تظبط ترا الطريقتين اللي عطيتك صحيحتين راجع الفنكشنات اللي مسويها انت

Link to comment

كودك زابط بس المشكلة منك

شوف المثال ذا ع نفس كودك !

هذا خطأ ؟

function closeWindow1 ( wnd )
  guiSetVisible ( wnd , false )
end

local Functions = { 
[1] = { Button = join , Function = joinJob },
[2] = { Button = ex , Function = closeWindow },
[3] = { Button = leave , Function = leaveJob },
[4] = { Button = ex_1 , Function = closeWindow1 }
}


addEventHandler("onClientGUIClick",resourceRoot,function()
for index = 1 , #Functions do 
if ( source == Functions [ index ] [ "Button" ] ) then 
Functions [ index ] [ "Function" ] ()
end
end
end
)

أما الصحيح فهذا

function closeWindow1 ( wnd )
  guiSetVisible ( wnd , false )
end

local Functions = { 
[1] = { Button = join , Function = joinJob },
[2] = { Button = ex , Function = closeWindow },
[3] = { Button = leave , Function = leaveJob },
[4] = { Button = ex_1 , Function = closeWindow1 }
}


addEventHandler("onClientGUIClick",resourceRoot,function()
for index = 1 , #Functions do 
if ( source == Functions [ index ] [ "Button" ] ) then 
Functions [ index ] [ "Function" ] ( wnd2 )
end
end
end
)

 

  • Like 1
Link to comment

@iMr.WiFi..! ماعليش مشكور كودك ظبط 

2 minutes ago, #_iMr.[E]coo said:

كودك زابط بس المشكلة منك

شوف المثال ذا ع نفس كودك !

هذا خطأ ؟


function closeWindow1 ( wnd )
  guiSetVisible ( wnd , false )
end

local Functions = { 
[1] = { Button = join , Function = joinJob },
[2] = { Button = ex , Function = closeWindow },
[3] = { Button = leave , Function = leaveJob },
[4] = { Button = ex_1 , Function = closeWindow1 }
}


addEventHandler("onClientGUIClick",resourceRoot,function()
for index = 1 , #Functions do 
if ( source == Functions [ index ] [ "Button" ] ) then 
Functions [ index ] [ "Function" ] ()
end
end
end
)

أما الصحيح فهذا


function closeWindow1 ( wnd )
  guiSetVisible ( wnd , false )
end

local Functions = { 
[1] = { Button = join , Function = joinJob },
[2] = { Button = ex , Function = closeWindow },
[3] = { Button = leave , Function = leaveJob },
[4] = { Button = ex_1 , Function = closeWindow1 }
}


addEventHandler("onClientGUIClick",resourceRoot,function()
for index = 1 , #Functions do 
if ( source == Functions [ index ] [ "Button" ] ) then 
Functions [ index ] [ "Function" ] ( wnd2 )
end
end
end
)

 

كودي صحيح بس مادري ليش مو راضي يشتغل

بالنسبة للكود حقك سطر 16 ليه wnd2 ?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...