SnoopCat Posted April 7, 2011 Share Posted April 7, 2011 hey i need to know how i can make a code to show random pictures in this case i will use race as example. g_GUI['travelImage'] = guiCreateStaticImage(screenWidth/2-400, screenHeight/2-300,800, 600, 'img/travelling.png', false, nil) how i can make that code to show diferent images each changemap. thx Link to comment
proracer Posted April 7, 2011 Share Posted April 7, 2011 In race/race_client.lua, go to line: 132-140 - you should see TravelScreen.init function. Try it replace with this: function TravelScreen.init() local screenWidth, screenHeight = guiGetScreenSize() local randomImages = {'img/travelling1.png','img/travelling2.png','img/travelling3.png'} g_GUI['travelImage'] = guiCreateStaticImage(screenWidth/2-256, screenHeight/2-90, 512, 256, tostring(randomImages[math.random(1,3)]), false, nil) g_dxGUI['travelText1'] = dxText:create('Travelling to', screenWidth/2, screenHeight/2-130, false, 'bankgothic', 0.60, 'center' ) g_dxGUI['travelText2'] = dxText:create('', screenWidth/2, screenHeight/2-100, false, 'bankgothic', 0.70, 'center' ) g_dxGUI['travelText1']:color(240,240,240) hideGUIComponents('travelImage', 'travelText1', 'travelText2') end Also you must have 3 pictures: travelling1.png,travelling2.png etc... you can change however you want. Link to comment
SnoopCat Posted April 7, 2011 Author Share Posted April 7, 2011 is it not working images are not showing Link to comment
proracer Posted April 8, 2011 Share Posted April 8, 2011 Any errors? Did you put 3 images correctly there and named them as it is in the table: "randomImages"? Link to comment
Dre-+- Posted April 8, 2011 Share Posted April 8, 2011 local imgTable = { "img/travelling.png","img/image2.png","img/image3.png","img/image4.png" } g_GUI['travelImage'] = guiCreateStaticImage(screenWidth/2-400, screenHeight/2-300,800, 600, imgTable[math.random(#imgTable)], false, nil) Link to comment
proracer Posted April 8, 2011 Share Posted April 8, 2011 Dre, isn't that the same as mine? Link to comment
Castillo Posted April 8, 2011 Share Posted April 8, 2011 It is not, he has changed the table part, take a look again. Link to comment
SnoopCat Posted April 8, 2011 Author Share Posted April 8, 2011 this one is not working: local imgTable = { "img/travelling.png","img/image2.png","img/image3.png","img/image4.png" } g_GUI['travelImage'] = guiCreateStaticImage(screenWidth/2-400, screenHeight/2-300,800, 600, imgTable[math.random(#imgTable)], false, nil) and also checked if the name was wrong and it wasnt Link to comment
Castillo Posted April 9, 2011 Share Posted April 9, 2011 Don't double-post!, wait for an answer. Link to comment
Moderators Citizen Posted April 9, 2011 Moderators Share Posted April 9, 2011 Maybe try this: local imgTable = { "img/travelling.png","img/image2.png","img/image3.png","img/image4.png" } g_GUI['travelImage'] = guiCreateStaticImage(screenWidth/2-400, screenHeight/2-300,800, 600, ""..imgTable[math.random(#imgTable)], false) if it don't work, try this: local ran = math.random(1,3) outputChatBox("img/travelImage"..ran) g_GUI['travelImage'] = guiCreateStaticImage(screenWidth/2-400, screenHeight/2-300,800, 600, "img/travelImage"..ran, false) and rename your images like this: 'travelImage3.png' or 'travelImage2.png' or 'travelImage3.png' etc If those codes don't works, it's maybe because the path is wrong ( the image aren't in the 'img' folder ) or those images aren't in the png format or you there aren't in your meta.xml Link to comment
SnoopCat Posted April 9, 2011 Author Share Posted April 9, 2011 i checked if all its correct images are in img folder, they are in the meta and i cheked the name also... the thing i cant understand in your second code its: local ran = math.random(1,3) outputChatBox("img/travelImage"..ran) g_GUI['travelImage'] = guiCreateStaticImage(screenWidth/2-400, screenHeight/2-300,800, 600, "img/travelImage"..ran, false) why u used outputChatBox if its is to say something on the chat? well its not working Link to comment
proracer Posted April 9, 2011 Share Posted April 9, 2011 They are often used for debugging.Use /debugscript to check any errors.Check if it outputs to chatbox that on line 2. Link to comment
Moderators Citizen Posted April 9, 2011 Moderators Share Posted April 9, 2011 Yeah sorry my bad, I forgot the ".png" local ran = math.random(1,3) outputChatBox("img/travelImage"..ran..".png") g_GUI['travelImage'] = guiCreateStaticImage(screenWidth/2-400, screenHeight/2-300,800, 600, "img/travelImage"..ran..".png", false) 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