Jump to content

Changin' Image on click.


Karuzo

Recommended Posts

Posted

Hi Community,

so i have a question about dx Images.

I have a few images in a folder, and i named them all like 1, 2, 3 ,4, etc...

My Question is : How can i show the 2nd picture after the first if i click on my button ?

i know i have to count it +1 but how ?

i hope you could help me.

regards,

KRZO.

Posted

You can do something like this:

local images = { "images/1.png", "images/2.png", "images/3.png", "images/4.png" } 
  
local curIndex = 1 
  
addEventHandler( "onClientRender", root, 
function () 
    dxDrawImage(x, y, w, h, images[curIndex]) 
end ) 
  
addEventHandler( "onClientGUIClick", button, 
function () 
    curIndex = curIndex + 1 
end ) 

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

Ok thank you it worked.

but if i click often on the button it just goes on never stops.

so my question is : how cani say it should stop if it is on the last picture ?

Posted (edited)
  
addEventHandler( "onClientGUIClick", button, 
function () 
    if (curIndex == #images) then 
        return 
    end 
    curIndex = curIndex + 1 
end ) 

Edited by Guest

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

He didn't said that want it to go back to the 1st picture if it's on the last picture.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

Thank you guys for you replies, DNL291, your's is working perfectly.

I tried to make a left button also so i can press the left button to get a picture before if im on the last picture.

but that doesn't really work

addEventHandler( "onClientGUIClick", linksbut, 
function () 
    if (curIndex == #images) then 
        return 
    end 
    curIndex = curIndex - 1 
end ) 

Posted
addEventHandler( "onClientGUIClick", guiRoot, 
function () 
    if (source == nextPicButton) then 
        if (curIndex == #images) then 
            return 
        end 
        curIndex = curIndex - 1 
    elseif (source == previousPicButton) then 
        if (curIndex == 1) then 
            return 
        end 
        curIndex = curIndex - 1 
    end 
end ) 

nextPicButton and previousPicButton must be defined.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

What do you mean? onClientGUIClick is only for GUIs.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

Oh , didn't knew that, thx.

Well , it doesn't work either.

local images = { "images/photo/1.png", "images/photo/2.png", "images/photo/3.png"} 
  
local curIndex = 1  
  
addEventHandler( "onClientGUIClick", guiRoot, 
function () 
    if (source == rechtsbut) then 
        if (curIndex == #images) then 
            return 
        end 
        curIndex = curIndex - 1 
    elseif (source == linksbut) then 
        if (curIndex == 1) then 
            return 
        end 
        curIndex = curIndex - 1 
    end 
end ) 

After the first picture theres nothin.

Posted

That's because you're using curIndex = curIndex - 1 when click both buttons.

Please do not PM me with scripting related question nor support, use the forums instead.

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