Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Convert from json to lua?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 511

PostPosted: Sun Feb 06, 2022 2:48 am    Post subject: Convert from json to lua? Reply with quote

Is there's any way to make it?
JSON:
Code:
"Snapshots": {
        "Snapshot 1": "0, -2511.28, -672.99, 195.75",
        "Snapshot 10": "0, -2773.04, 783.45, 67.66",
        "Snapshot 11": "0, -2680.07, 1590.8, 143.53",
        "Snapshot 12": "0, -2476.75, 1543.44, 49.26",
        "Snapshot 13": "0, -1879.04, 1456.52, 9.34",
        "Snapshot 14": "0, -1561.55, 655.19, 56.52",
        "Snapshot 15": "0, -1325.15, 494.19, 26.83",
        "Snapshot 16": "0, -1941.41, 137.72, 37.83",
        "Snapshot 17": "0, -2153.23, 462.25, 103.27",
        "Snapshot 18": "0, -2243.96, 577.76, 49",
        "Snapshot 19": "0, -2051, 456, 167",
        "Snapshot 2": "0, -2723.63, -314.72, 55.79",
        "Snapshot 20": "0, -1951, 659, 81",
        "Snapshot 21": "0, -2064, 926, 63",
        "Snapshot 22": "0, -2357.33, 1017.01, 59.76",
        "Snapshot 23": "0, -2072, 1066, 74",
        "Snapshot 24": "0, -1744, 972.46, 156.89",
        "Snapshot 25": "0, -1941, 883, 68",
        "Snapshot 26": "0, -1839.51, 1086.88, 101.29",
        "Snapshot 27": "0, -1704.8, 1338, 14",
        "Snapshot 28": "0, -2346.62, 536.85, 86.02",
        "Snapshot 29": "0, -2443, 755, 49",
        "Snapshot 3": "0, -1737.71, -579.55, 26.19",
        "Snapshot 30": "0, -2765, 375, 15",
        "Snapshot 31": "0, -2880.31, -935.83, 40.82",
        "Snapshot 32": "0, -2083, -808, 69",
        "Snapshot 33": "0, -1954, -760, 53",
        "Snapshot 34": "0, -964.53, -331.59, 47.16",
        "Snapshot 35": "0, -1689, 51, 38",
        "Snapshot 36": "0, -2080, 256.05, 107",
        "Snapshot 37": "0, -2413, 331, 37",
        "Snapshot 38": "0, -2244.42, 731.32, 61.88",
        "Snapshot 39": "0, -2462, 369, 59",
        "Snapshot 4": "0, -1486.08, 920.04, 41.37",
        "Snapshot 40": "0, -1124.44, -153.15, 18.5",
        "Snapshot 41": "0, -1275.78, 53.68, 89.07",
        "Snapshot 42": "0, -2430, 38, 51",
        "Snapshot 43": "0, -2591, 162, 15",
        "Snapshot 44": "0, -2591, -16, 17",
        "Snapshot 45": "0, -2648, -5, 31",
        "Snapshot 46": "0, -2593, 56, 16",
        "Snapshot 47": "0, -1619.31, 1341.39, 11.3",
        "Snapshot 48": "0, -2307, 207, 42",
        "Snapshot 49": "0, -2343, -79, 38",
        "Snapshot 5": "0, -1269.82, 963.63, 130.37",
        "Snapshot 50": "0, -1906.66, 518.58, 61.71",
        "Snapshot 6": "0, -1650.01, 422, 21.17",
        "Snapshot 7": "0, -1851.72, -96.73, 24.37",
        "Snapshot 8": "0, -2732, -244, 19",
        "Snapshot 9": "0, -2802.75, 375.47, 36.59"
    },

I tried to get coordinates but from my lua knonwledge nothing make it successful
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sun Feb 06, 2022 4:10 am    Post subject: Reply with quote

You'd have to convert it to a table of tables.
Code:

local Snapshots = {
   ["Snapshot 1"] = { 0, -2511.28, -672.99, 195.75 },
   -- or
   Snapshot1 = { 0, -2511.28, -672.99, 195.75 },
   -- ...
}


But I'd use the json.lua module.
Code:
local jobj = [[{
   "Snapshots": {
        "Snapshot 1": "0, -2511.28, -672.99, 195.75",
        "Snapshot 10": "0, -2773.04, 783.45, 67.66",
        "Snapshot 11": "0, -2680.07, 1590.8, 143.53",
        "Snapshot 12": "0, -2476.75, 1543.44, 49.26",
        "Snapshot 13": "0, -1879.04, 1456.52, 9.34",
        "Snapshot 14": "0, -1561.55, 655.19, 56.52",
        "Snapshot 15": "0, -1325.15, 494.19, 26.83",
        "Snapshot 16": "0, -1941.41, 137.72, 37.83",
        "Snapshot 17": "0, -2153.23, 462.25, 103.27",
        "Snapshot 18": "0, -2243.96, 577.76, 49",
        "Snapshot 19": "0, -2051, 456, 167",
        "Snapshot 2": "0, -2723.63, -314.72, 55.79",
        "Snapshot 20": "0, -1951, 659, 81",
        "Snapshot 21": "0, -2064, 926, 63",
        "Snapshot 22": "0, -2357.33, 1017.01, 59.76",
        "Snapshot 23": "0, -2072, 1066, 74",
        "Snapshot 24": "0, -1744, 972.46, 156.89",
        "Snapshot 25": "0, -1941, 883, 68",
        "Snapshot 26": "0, -1839.51, 1086.88, 101.29",
        "Snapshot 27": "0, -1704.8, 1338, 14",
        "Snapshot 28": "0, -2346.62, 536.85, 86.02",
        "Snapshot 29": "0, -2443, 755, 49",
        "Snapshot 3": "0, -1737.71, -579.55, 26.19",
        "Snapshot 30": "0, -2765, 375, 15",
        "Snapshot 31": "0, -2880.31, -935.83, 40.82",
        "Snapshot 32": "0, -2083, -808, 69",
        "Snapshot 33": "0, -1954, -760, 53",
        "Snapshot 34": "0, -964.53, -331.59, 47.16",
        "Snapshot 35": "0, -1689, 51, 38",
        "Snapshot 36": "0, -2080, 256.05, 107",
        "Snapshot 37": "0, -2413, 331, 37",
        "Snapshot 38": "0, -2244.42, 731.32, 61.88",
        "Snapshot 39": "0, -2462, 369, 59",
        "Snapshot 4": "0, -1486.08, 920.04, 41.37",
        "Snapshot 40": "0, -1124.44, -153.15, 18.5",
        "Snapshot 41": "0, -1275.78, 53.68, 89.07",
        "Snapshot 42": "0, -2430, 38, 51",
        "Snapshot 43": "0, -2591, 162, 15",
        "Snapshot 44": "0, -2591, -16, 17",
        "Snapshot 45": "0, -2648, -5, 31",
        "Snapshot 46": "0, -2593, 56, 16",
        "Snapshot 47": "0, -1619.31, 1341.39, 11.3",
        "Snapshot 48": "0, -2307, 207, 42",
        "Snapshot 49": "0, -2343, -79, 38",
        "Snapshot 5": "0, -1269.82, 963.63, 130.37",
        "Snapshot 50": "0, -1906.66, 518.58, 61.71",
        "Snapshot 6": "0, -1650.01, 422, 21.17",
        "Snapshot 7": "0, -1851.72, -96.73, 24.37",
        "Snapshot 8": "0, -2732, -244, 19",
        "Snapshot 9": "0, -2802.75, 375.47, 36.59"
    }
}]]
local json = require('json')
local data = json.decode(jobj)

_________________
Back to top
View user's profile Send private message Visit poster's website
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 511

PostPosted: Sun Feb 06, 2022 4:19 am    Post subject: Reply with quote

Like this:
Code:
[1] = CVector3D:New(x,y,z) --CVector3D:New registering x,y,z
Back to top
View user's profile Send private message
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 511

PostPosted: Wed Feb 09, 2022 12:42 pm    Post subject: Reply with quote

bump time
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Wed Feb 09, 2022 6:54 pm    Post subject: Reply with quote

Yeah I'm not sure what you mean, I showed you how to convert from json data to a lua table.

I mean to access the lua table's data you'd just index the table.

Code:

print('X = ', data['Snapshot 1'][2])
print('Y = ', data['Snapshot 1'][3])
print('Z = ', data['Snapshot 1'][4])


But this is assuming the structure is; unknow, X, Y, Z.

_________________
Back to top
View user's profile Send private message Visit poster's website
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 511

PostPosted: Wed Feb 09, 2022 11:41 pm    Post subject: Reply with quote

Thx
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites