I am currently developing a Telegram application for a gaming project. The process involves multiple steps: Step1 requires me to call the MYSQL database to fetch data in lua. Step2 involves sending the table data to my NUI in the telegram.js file. Step3 is focused on converting the string into an array.
The structure of the data being pulled is perfectly represented in my telegram.js file:
var Atest = [
(a1 = [7, 1, 'This is a test', 1, '05:30:35pm', '09/23/2021', 1]),
(b1 = [7, 1, 'Test Test', 1, '05:40:35pm', '09/26/2021', 2]),
];
While this setup works well within the .js file, encountering issues arise when trying to extract data from a string received from the telegram.lua file and convert it into an array.
for (const [key, value] of Object.entries(Atest)) {
console.log(`${key}: ${value}`);
}
0: 7, 1, This is a test, 1, 05:30:35pm, 09/23/2021, 1
1: "diff string ect..."
A particular challenge faced is accessing the inner values when processing the string. While the provided example functions correctly due to its location in the .js file, extracting data from a string fails to register inner arrays using index references.
Even utilizing for k,v in pair do
does not yield accurate results, particularly when maintaining the order of elements. An efficient solution would involve converting the string into a complete array structure.
The code snippet essential for my menu program is detailed below:
telegram.js
function newMessages(nTT) {
for (const [key, value] of Object.entries(nTT)) {
console.log(`${key}: ${value}`);
}
sleep(100);
console.log(nTT);
for (const [k, v] of nTT.entries()) {
var split_date = v[5].split('/');
var newb = document.createElement('a');
var newb_i = document.createElement('input');
// rest of the code block...
}
check_checked();
disable_tele_input();
}
Inevitably, modifying the data structure to use id values instead of numerical indices when iterating through it will be necessary. Such adjustments should facilitate smoother integration with existing database records and Lua strings.
Despite investing significant time attempting various approaches like arr.push, split(), or RegExp matching to reconstruct the string inside JavaScript as an array, the desired outcome remains elusive. Assistance in resolving this predicament is highly appreciated.
The actual dataset extracted from the MySQL database is as follows:
MSYQL DB
// Data entries...
This represents the Lua script snippet handling the sorting:
telegram_sv.lua
// Lua scripting logic...
telegram.js
// Further JavaScript functionality...
Your assistance and guidance are greatly appreciated!
¯\_(ツ)_/¯