Einheit-101 Posted October 8, 2011 Posted October 8, 2011 (edited) Hey guys, I got a little Problem and dont know why. This part of my script creates a static image called "image". the Server calls the second function and wants to replace this image with another one. But the script returns: warning: cscript.lua:15: Bad argument @ 'guiStaticImageLoadImage' [Expected gui-element at argument 1, got nil] But this gui element is defined in "function imager()" with "image = guiCreateStaticImage( x,y, 150, 150, "rang/r1.png", false )" why does it say "nil"? image = nil function imager() local xp,yp = guiGetScreenSize() x = xp/2 - 150/2+500 y = yp/2 - 250 image = guiCreateStaticImage( x,y, 150, 150, "rang/r1.png", false ) end addEventHandler ( "onClientResourceStart",getResourceRootElement(getThisResource()), imager) for i = 1, 23 do addEvent ( "r"..tostring ( i ), true ) addEventHandler ( "r"..tostring ( i ), getRootElement ( ), function ( image ) guiStaticImageLoadImage( image, "rang/r"..tostring( i )..".png" ) lvlup = playSound("lvlup.mp3",false) setSoundVolume(lvlup,1) end ) end Edited October 8, 2011 by Guest
^Dev-PoinT^ Posted October 8, 2011 Posted October 8, 2011 Try This function imager() local xp,yp = guiGetScreenSize() x = xp/2 - 150/2+500 y = yp/2 - 250 image = guiCreateStaticImage( x,y, 150, 150, "rang/r1.png", false ) end addEventHandler ( "onClientResourceStart",getResourceRootElement(getThisResource()), imager) for i = 1, 23 do addEvent ( "r"..tostring ( i ), true ) addEventHandler ( "r"..tostring ( i ), getRootElement ( ), function ( image ) guiStaticImageLoadImage ( image, "rang/r"..tostring( i )..".png" ) lvlup = playSound("lvlup.mp3",false) setSoundVolume(lvlup,1) end ) end
Einheit-101 Posted October 8, 2011 Author Posted October 8, 2011 Hmm the only difference is the deleted "image = nil" ? i have tried it, but still -> warning: cscript.lua:15: Bad argument @ 'guiStaticImageLoadImage' [Expected gui-element at argument 1, got nil]
^Dev-PoinT^ Posted October 8, 2011 Posted October 8, 2011 guiStaticImageLoadImage ( image, "rang/r1"..tostring( i )..".png" ) from r to r1
Einheit-101 Posted October 8, 2011 Author Posted October 8, 2011 It still does not work Maybe the error is in the server script, but Everything works fine, the sound plays, the debug outputChatBox works, it draws the first picture. But it does no "guiStaticImageLoadImage".
Castillo Posted October 8, 2011 Posted October 8, 2011 Are you sure the image is created correctly? try adding some debug outputs into "imager" function.
Einheit-101 Posted October 8, 2011 Author Posted October 8, 2011 Yes, the image is created correctly, i can see it on the screen. Or does that not mean, that it is created correctly? o_O EDIT::: I changed the created picture`s name to "r2" (it was "r1" before) and now it creates the second picture correctly.
Castillo Posted October 8, 2011 Posted October 8, 2011 I've noticed this in your script: for i = 1, 23 do addEvent ( "r"..tostring ( i ), true ) addEventHandler ( "r"..tostring ( i ), getRootElement ( ), function ( image ) -- [b][u]You are replacing your current variable with this one (I don't know where you sent it from).[/u][/b] guiStaticImageLoadImage ( image, "rang/r"..tostring( i )..".png" ) lvlup = playSound("lvlup.mp3",false) setSoundVolume(lvlup,1) end ) end
Einheit-101 Posted October 8, 2011 Author Posted October 8, 2011 Castillo, youre noticing right. Im replacing the correct image with an non-existing one, i just dont know how i came to this stupid idea. I fixed it and it works fine, i just have to test it with more than one player and all pictures. Thanks to all who tried to help me! I will ask again if i need further help
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