Jump to content

guiStaticImageLoadImage returns bad argument


Einheit-101

Recommended Posts

Posted (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 by Guest
Posted

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 
  

Posted

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]

Posted

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

Posted

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.

Posted

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 

Posted

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

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