Jump to content

Help getting button data on mouse hover


audi868

Recommended Posts

Posted (edited)

Doesn't sets the memo text to the info,

  
root = getRootElement() 
sx,sy = guiGetScreenSize() 
addCommandHandler("shop",function() 
shop = {} 
shop['window'] = guiCreateWindow((sx/2)-320,(sy/2)-240,640,480,"Shop",false) 
shop['info1'] = guiCreateMemo(0.3644,0.1812,0.4759,0.3068,"",true,shop['window']) 
shop['info2'] = guiCreateMemo(0.3644,0.6039,0.4759,0.3068,"",true,shop['window']) 
loadShop() 
end 
) 
  
function itm1(x,y,w,h,text,info) 
    local btn = guiCreateButton(x,y,w,h,text,true,shop['window']) 
    setElementData(btn,"infoindex",1) 
    setElementData(btn,"info",info) 
end 
  
function itm2(x,y,w,h,text,info) 
    local btn = guiCreateButton(x,y,w,h,text,true,shop['window']) 
    setElementData(btn,"infoindex",2) 
    setElementData(btn,"info",info) 
end 
  
function loadShop() 
    itm1(0.1714,0.1787,0.1597,0.0652,"Flip","Flip your car for $500") -- this for test 
end 
  
function getItemInfo() 
    if getElementData(source,"info") then 
    local infoindex = getElementData(source,"infoindex") 
    local info = getElementData(source,"info") 
    local infoMemo = "shop['info"..infoindex.."']" 
    guiSetText(infoMemo,info) 
    end 
end 
  
addEventHandler("onClientMouseEnter",root,getItemInfo) 

I tried to debug using outputChatBox(info) under getItemInfo works but still doesn't works for the memo

Edited by Guest
Posted

You are using a variable as a gui-element, which won't work of course.

root = getRootElement() 
sx,sy = guiGetScreenSize() 
addCommandHandler("shop",function() 
shop = {} 
shop['window'] = guiCreateWindow((sx/2)-320,(sy/2)-240,640,480,"Shop",false) 
shop['info1'] = guiCreateMemo(0.3644,0.1812,0.4759,0.3068,"",true,shop['window']) 
shop['info2'] = guiCreateMemo(0.3644,0.6039,0.4759,0.3068,"",true,shop['window']) 
end 
) 
  
function itm1(x,y,w,h,text,info) 
    local btn = guiCreateButton(x,y,w,h,text,true,shop['window']) 
    setElementData(btn,"infoindex",1) 
    setElementData(btn,"info",info) 
end 
  
function itm2(x,y,w,h,text,info) 
    local btn = guiCreateButton(x,y,w,h,text,true,shop['window']) 
    setElementData(btn,"infoindex",2) 
    setElementData(btn,"info",info) 
end 
  
function loadShop() 
    itm1(0.1714,0.1787,0.1597,0.0652,"Flip","Flip your car for $500") -- this for test 
end 
  
function getItemInfo() 
    if getElementData(source,"info") then 
    local infoindex = getElementData(source,"infoindex") 
    local info = getElementData(source,"info") 
    local infoMemo = "shop['info"..infoindex.."']" 
    guiSetText(shop['info1'],info) 
    end 
end 
addEventHandler("onClientMouseEnter",root,getItemInfo) 

Not sure if that's waht you wanted.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
    guiSetText(shop['info1'],info) 

how should I get in which memo would the text be placed then? cuz I have two memos

P/S:

You are using a variable as a gui-element, which won't work of course.

Where so? I mean line?

Posted (edited)

Ok, I get what you was trying to do now, but your problem was that you put infoMemo as a string.

root = getRootElement() 
sx,sy = guiGetScreenSize() 
addCommandHandler("shop",function() 
shop = {} 
shop['window'] = guiCreateWindow((sx/2)-320,(sy/2)-240,640,480,"Shop",false) 
shop['info1'] = guiCreateMemo(0.3644,0.1812,0.4759,0.3068,"",true,shop['window']) 
shop['info2'] = guiCreateMemo(0.3644,0.6039,0.4759,0.3068,"",true,shop['window']) 
end 
) 
  
function itm1(x,y,w,h,text,info) 
    local btn = guiCreateButton(x,y,w,h,text,true,shop['window']) 
    setElementData(btn,"infoindex",1) 
    setElementData(btn,"info",info) 
end 
  
function itm2(x,y,w,h,text,info) 
    local btn = guiCreateButton(x,y,w,h,text,true,shop['window']) 
    setElementData(btn,"infoindex",2) 
    setElementData(btn,"info",info) 
end 
  
function loadShop() 
    itm1(0.1714,0.1787,0.1597,0.0652,"Flip","Flip your car for $500") -- this for test 
end 
  
function getItemInfo() 
    if getElementData(source,"info") then 
    local infoindex = getElementData(source,"infoindex") 
    local info = getElementData(source,"info") 
    local infoMemo = shop["info".. infoindex] 
    guiSetText(infoMemo,info) 
    end 
end 
addEventHandler("onClientMouseEnter",root,getItemInfo) 

Should do what you wanted now.

Edited by Guest

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

That's the same I last posted but without the variable, and my code was working, I tested it.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Oh, my bad, I didn't noticed about that :oops: .

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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