Jump to content

Problem with a label and guiGetText()


FSXTim

Recommended Posts

Hello,

if the player press the button 'sodButton1' and the text of the label is '1', the outputChatBox has to say 'Test', but it doesn't, although the text of the label is '1'.

sod1 = guiCreateLabel(0.2200,0.1500,0.0455,0.0485,"1",true,sudoku_Window) 

function checkSod (state) 
    if state == "left" then 
        if source == sodButton1 then 
            if guiGetText(sod1) == "1" then 
                local player = getLocalPlayer() 
                outputChatBox("Test", player) 
            end  
        end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement(), checkSod)  

Greets

Link to comment

No errors in the debugscript.

This doesn't work:

sod1 = guiCreateLabel(0.2200,0.1500,0.0455,0.0485,"1",true,sudoku_Window) 
  
function checkSod (state) 
    if state == "left" then 
        if source == sodButton1 then 
            if guiGetText(sod1) == "1" then 
                local player = getLocalPlayer() 
                outputChatBox("Test", player) 
            end  
        end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement(), checkSod)  

But this works:

function checkSod (state) 
    if state == "left" then 
        if source == sodButton1 then 
            sod1 = guiCreateLabel(0.2200,0.1500,0.0455,0.0485,"1",true,sudoku_Window)    
            if guiGetText(sod1) == "1" then 
                local player = getLocalPlayer() 
                outputChatBox("Test", player) 
            end  
        end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement(), checkSod)  

But I need to make it working with the first way.

Greets

Edited by Guest
Link to comment

First argument of: onClientGUIClick is the mouse button used, not the state.

function checkSod ( button, state ) 
    if ( state == "left" ) then 
        if ( source == sodButton1 ) then 
            if ( guiGetText ( sod1 ) == "1" ) then 
                outputChatBox ( "Test" ) -- This function has no visibleTo argument in the client side. 
            end  
        end 
    end 
end 
addEventHandler ( "onClientGUIClick", guiRoot, checkSod ) 

Link to comment
function checkSod ( button, state ) 
    if (state == "left") then 
        if (source == sodButton1) then 
            if (guiGetText(sod1 ) == "1") then 
                outputChatBox ("Test") 
            end  
        end 
    end 
end 
addEventHandler ("onClientGUIClick", getRootElement(), checkSod) 

Now the chatbox doesn't say anything although the text in the label is '1'!

Greets

Edited by Guest
Link to comment
function checkSod ( button, state ) 
        if ( source == sodButton1 ) then 
            if ( guiGetText ( sod1 ) == "1" ) then 
                outputChatBox ( "Test" ) 
        end 
    end 
end 
addEventHandler ( "onClientGUIClick", guiRoot, checkSod ) 

If that doesn't work, then post your entire script.

Link to comment

This also doesn't work.

The script:

x,y = guiGetScreenSize() 
sudoku_Window = guiCreateWindow(x/10.0 - 110,y/2.5 - 165,220,330,"",false) 
sodButton1 = guiCreateButton(0.0909,0.7182,0.2409,0.0515,"Prüfen",true,sudoku_Window) 
guiSetFont(sodButton1,"default-bold-small") 
sod1 = guiCreateLabel(0.2200,0.1500,0.0455,0.0485,"1",true,sudoku_Window) 
  
function checkSod ( button, state ) 
        if ( source == sodButton1 ) then 
            if ( guiGetText ( sod1 ) == "1" ) then 
                outputChatBox ( "Test" ) 
        end 
    end 
end 
addEventHandler ( "onClientGUIClick", guiRoot, checkSod ) 

Greets

Edited by Guest
Link to comment
Sorry, I forgot it. I edited my last post.

#Edit: I found a solution:

function checkSod (state) 
    if state == "left" then 
        if source == sodButton1 then 
            if guiGetText(sod1) == "1" then 
                outputChatBox("Test") 
            end  
        end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement(), checkSod)  

Thanks at all!

Greets

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