Jump to content

func fileOpen in the client script does not work.


uriid1

Recommended Posts

Hello.
The FileOpen function works for me without problems in the server script.

But it does not work on the client side.

meta.xml

<meta>
    <!-- Information -->
        <info name="nine" author="uriid1" version="0" type="script" />
    
    <!-- Scripts -->
        <script src="main.lua" type="client" />


    <!-- MTA Version-->
        <min_mta_version server="1.5.8" />
</meta>

 

main.lua

local hFile = fileOpen("test.txt", true)       -- attempt to open the file (read only)
if hFile then                                  -- check if it was successfully opened
    local buffer
    while not fileIsEOF(hFile) do              -- as long as we're not at the end of the file...
        buffer = fileRead(hFile, 500)          -- ... read the next 500 bytes...
        outputConsole(buffer)                  -- ... and output them to the console
    end
    fileClose(hFile)                           -- close the file once we're done with it
else
    outputConsole("Unable to open test.txt")
end

test.txt it is located in the root of the resource and contains the text " Hello World!"

I just realized that I didn't specify in meta.xml file test.txt.

now I wonder if it is possible to somehow load a dynamically modified file

Link to comment

MTA expects files that are specified inside meta.xml to stay immutable during the runtime of the resource. If you want to synchronize data that changes during runtime please consider using the triggerServerEvent/triggerClientEvent API instead.

Link to comment
3 hours ago, The_GTA said:

MTA expects files that are specified inside meta.xml to stay immutable during the runtime of the resource. If you want to synchronize data that changes during runtime please consider using the triggerServerEvent/triggerClientEvent API instead.

Thanks. 
Interestingly, it turns out that you can implement something like love code by changing the resource code on the server, it would change on the client.

Link to comment
1 minute ago, uriid1 said:

Thanks. 
Interestingly, it turns out that you can implement something like love code by changing the resource code on the server, it would change on the client.

Consider what happens if clients are already connected to your server. Unless you restart your resource they will not see the changes. Because of that changing resource files is not recommended but I have been tinkering around with it in the past (resource "resedit").

Link to comment
12 minutes ago, The_GTA said:

Consider what happens if clients are already connected to your server. Unless you restart your resource they will not see the changes. Because of that changing resource files is not recommended but I have been tinkering around with it in the past (resource "resedit").

Well, I mean, if the server script will tell the client that some file has changed (via triggerServerEvent/triggerClientEvent). Just checking if the size of this file has changed.

In this case, Clint could download it again. 

And if we talk about scripts,it was possible to implement LiveCode/HotReload using loadstring. But this is of course stupid :)

Link to comment
4 minutes ago, uriid1 said:

And if we talk about scripts,it was possible to implement LiveCode/HotReload using loadstring. But this is of course stupid :)

I unironically agree. Reason: reverting the changes of single Lua scripts is not documented/defined/expected (Lua table contents, created MTA elements, registered callbacks, ...). And patching is not defined either since the Lua VM state is too complicated.

Edited by The_GTA
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...