Jump to content

Send data


mmdRexo

Recommended Posts

8 hours ago, mmdRexo said:

hi i need to send data 

Lua -> js -> html

i want to show player data in html value

To transfer data from Lua to JavaScript and display it in HTML, you can do it as follows:

In your Lua code, generate the data that you want to transfer to JavaScript. You can do this using the print statement or other methods of writing data to a file.

In your JavaScript code, add code that retrieves the data from the file generated by Lua and saves it to a variable. You can do this using the fetch function or XMLHttpRequest.

In your HTML code, add code that displays the data saved in the JavaScript variable. You can do this using the <script> tag or the document.write function.

Here is an example code that illustrates the above process:


 

-- Lua code
player_name = "John Doe"
player_score = 1000

-- save data to file
file = io.open("player_data.txt", "w")
file:write(player_name .. "\n")
file:write(player_score .. "\n")
file:close()

-- JavaScript code
// retrieve data from file
fetch("player_data.txt")
  .then(response => response.text())
  .then(data => {
    // split data by newline character
    var data_lines = data.split("\n")
    // save data to variables
    var player_name = data_lines[0]
    var player_score = data_lines[1]
    // display data in HTML
    document.write("Player name: " + player_name + "<br>")
    document.write("Player score: " + player_score + "<br>")
  })
  .catch(error => console.error(error))

 

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