Jump to content

fileExists / dxDrawImage


MrCode

Recommended Posts

Good day, What is the best way to check if a or (any) file actually exists while using onClientRender? I'm using onClientRender to draw a PNG image located in another resource but if the image is missing (not yet downloaded by the client), then still, debug would output an error message. "Error loading image @ 'dxDrawImage' [:resource2/images/image.png]"
To avoid that, should the file path become some type of local variable or? I'm not sure because I've tried a bunch of different ways and each of them have the same result.

	-- resource1: onClientRender

	if fileExists ( ":resource2/images/image.png" ) then
	   dxDrawImage ( sx, sy, 32, 32, ":resource2/images/image.png" )
	end

	-- Debug: { Error loading image @ 'dxDrawImage' [:resource2/images/image.png] } (x1)


 

Edited by MrCode
Incorrect info
Link to comment

Sorry, I wrote the wrong debug output. The actual error is: Error loading image @ 'dxDrawImage' [:resource2/images/image.png]

The PNG file in resource2 does indeed exist in the meta.xml, everything is in order with the path and the image does render normal. It just briefly outputs an error before it renders. It's like fileExists returns true while there is a (clear path to image.png), then when using dxDrawImage it has problems loading the image because the image.png itself is not yet recognized as a PNG file by the MTA client. So perhaps fileExists being used onClientRender is a bad move..

Link to comment
  • Moderators
On 21/01/2025 at 19:10, MrCode said:

So perhaps fileExists being used onClientRender

I wouldn't run that function either in combination with onClientRender.

Since you are fetching the file from another resource, you could increase or decrease the download priority for either resource.

https://wiki.multitheftauto.com/wiki/Meta.xml

Or just wait a little bit longer before start rendering.
(I also recommend to convert the image into a texture before rendering)

Link to comment

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