MOHAKO Posted July 10, 2013 Share Posted July 10, 2013 (edited) Hello guys. Amm, I'm here for a really stupid question, but... here it is - I want to create 'something' which will be shown multiple times, multiple times depending on some count (see example below). e.g. if the count will be 5, it will print 'dxDrawRectangle' 5 times. Anyone can help me out? Edited July 11, 2013 by Guest Link to comment
MOHAKO Posted July 10, 2013 Author Share Posted July 10, 2013 Yeah... But when it's used in "onClientRender", the result being printed infinity times... e.g screenY, count = nil function one_bla() -- some code screenY = 20 -- another code gets the count of something count = 5 -- sets the count from something addEventHandler("onClientRender", getRootElement(), drawBg) end function drawBg() for i = 1, count do dxDrawRectangle(0, screenY, 256, 64, tocolor(0,0,0,100), false) screenY = screenY + 66 end end Link to comment
myonlake Posted July 10, 2013 Share Posted July 10, 2013 I don't know what's the point in this. onClientRender renders infinitely corresponding to the client's rendering time and I am not sure why do you want a "count" in it. Do you want to show it a limited amount of time like five seconds or what is it? Link to comment
MOHAKO Posted July 10, 2013 Author Share Posted July 10, 2013 Well, the point is - in the first function, it'll select the characters from the database and print them in the character selection screen. The second function, which renders the 'dxDrawRectangle', will be used as background for one character... If account has two characters, it'll draw another 'dxDrawRectangle', but in the second 'dxDrawRectangle', the Y coordinates will be changed by +66 pixels, You got me? Link to comment
myonlake Posted July 10, 2013 Share Posted July 10, 2013 Oh, okay. The following worked fine for me. local screenY, count, space = 0, 0, 66 -- y-coordinate, the amount of boxes and the multiplier how far the boxes are set from each other -- function to draw the rectangles function drawBg() for i=1,count do -- repeat until we reach the amount of boxes dxDrawRectangle(0, screenY+(space*i), 256, 64, tocolor(0, 0, 0, 100), false) -- draw the rectangle so that it counts the space multiplied with the box count incremented with the y-coordinate end end -- initialization for background rendering function initBg() screenY, count = 20, 5 -- set the variables how we want them addEventHandler("onClientRender", root, drawBg) -- trigger the event handler for the rendering end initBg() -- launch the initialization It's kinda tricky but to be honest mathematics are always the answer to the toughest questions after all. It usually solves most of the problems when trying to be accurate. In this case it was rather simple: 20+(5*count) Link to comment
MOHAKO Posted July 10, 2013 Author Share Posted July 10, 2013 Thank you so much myonlake. It worked but with some improvements. Thank you again, you've earned a cookie from me. 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