Karuzo Posted January 30, 2014 Share Posted January 30, 2014 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. Link to comment
DNL291 Posted January 30, 2014 Share Posted January 30, 2014 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 ) Link to comment
Karuzo Posted January 30, 2014 Author Share Posted January 30, 2014 and if want to go back just do curIndex - 1? Link to comment
Karuzo Posted January 30, 2014 Author Share Posted January 30, 2014 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 ? Link to comment
DNL291 Posted January 30, 2014 Share Posted January 30, 2014 (edited) addEventHandler( "onClientGUIClick", button, function () if (curIndex == #images) then return end curIndex = curIndex + 1 end ) Edited January 30, 2014 by Guest Link to comment
Gallardo9944 Posted January 30, 2014 Share Posted January 30, 2014 add a simple check in the click event: addEventHandler( "onClientGUIClick", button, function () if not fileExists(images[curIndex]) then curIndex = 1 else curIndex = curIndex + 1 end end Link to comment
DNL291 Posted January 30, 2014 Share Posted January 30, 2014 He didn't said that want it to go back to the 1st picture if it's on the last picture. Link to comment
Karuzo Posted January 30, 2014 Author Share Posted January 30, 2014 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 ) Link to comment
DNL291 Posted January 30, 2014 Share Posted January 30, 2014 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. Link to comment
Karuzo Posted January 30, 2014 Author Share Posted January 30, 2014 What about guiRoot ? i've did this with dx. Link to comment
DNL291 Posted January 30, 2014 Share Posted January 30, 2014 What do you mean? onClientGUIClick is only for GUIs. Link to comment
Karuzo Posted January 30, 2014 Author Share Posted January 30, 2014 i know. but what do you mean with guiRoot ? What is that ? Link to comment
DNL291 Posted January 30, 2014 Share Posted January 30, 2014 It's a predefined variable. I use it just to avoid root (getRootElement()). Here's the list of predefined variables: viewtopic.php?f=91&t=39678 Link to comment
Karuzo Posted January 30, 2014 Author Share Posted January 30, 2014 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. Link to comment
DNL291 Posted January 30, 2014 Share Posted January 30, 2014 That's because you're using curIndex = curIndex - 1 when click both buttons. Link to comment
Karuzo Posted January 30, 2014 Author Share Posted January 30, 2014 Oh god, what a stupid mistake. Now it works. Thank you very much. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now