Jump to content

[Ошибка образца] Про нажатие кнопки(Мне так кажется)


Recommended Posts

-- When client's resource starts, create the GUI 
function initGUI( ) 
    -- Create our button 
    btnOutput = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true ) 
  
    -- And attach our button to the outputEditBox function 
    addEventHandler ( "onClientGUIClick", btnOutput, outputEditBox, false ) 
  
    -- Create an edit box and define it as "editBox". 
    editBox = guiCreateEdit( 0.3, 0.1, 0.4, 0.1, "Type your message here!", true ) 
    guiEditSetMaxLength ( editBox, 128 ) -- The max chatbox text length is 128, so force this 
end 
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), initGUI ) 
  
-- Setup our function to output the message to the chatbox 
function outputEditBox ( button ) 
    if button == "left" then 
        local text = guiGetText ( editBox )-- Get the text from the edit box 
        outputChatBox ( text ) -- Output that text 
    end 
end 

Как эта переменная

-- Create our button 
    btnOutput = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true ) 

вяжется с этой

if button == "left" then 

https://wiki.multitheftauto.com/wiki/OnClientGUIClick

Link to comment

Ответ на твой вопрос: Никак, это разные переменные. btnOutput это элемент созданной кнопки (в смысле прямоугольник черный) к которой позже привязывается событие "onClientGUIClick" (к элементу), а button это типа кнопки мыши, вследствие нажатии которой и произошло событие "onClientGUIClick" (при условии что курсор был наведен на кнопку btnOutput) в нашем случает левая кнопка "left"

Пример приведенный на вики полностью верный, ты его просто не понял)

Посмотри ещё раз каждую переменную в примере, подумай что каждая из них представляет из себя.

И просмотри описания каждого события использованного в нем и каждой функции. Словом, разберись в самом принципе скрипта, во всей его логике

Это будет не лишнем и если сделаешь это, то таких вопросов не возникнет больше ;)

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...