More documentation and a .yml parser would be fantastic, though speed is always nice too
Why do you need a .yml parser? Just use JSON instead, it's much nicer.
[QUOTE=Programmer;34965170]Why do you need a .yml parser? Just use JSON instead, it's much nicer.[/QUOTE]
It is - the goal was to write an addon that functions identical to the bukkit "Waypoint" addon, and make it read the same file format so that anyone who ran a bukkit server could switch to luacraft and not have to lose all their data or learn how to convert the two file formats. It might be easier to just write a separate program in C++ though that does the conversion for them
Also it seems like the LookAt() function is buggy.
[CODE]hook.Add("render.gameoverlay","OnRender",function()
closest = ents.GetClosestToEntity(LocalPlayer())
LocalPlayer():LookAt(closest)
end)
[/CODE]
I spawned a pig close to me but it justs looks at the horizon of the map.
now I'm not claiming to know how LookAt is supposed to work, but aren't you telling the LocalPlayer to look at an entity there?
you probably want:
[lua]closest:LookAt(LocalPlayer())[/lua]
[QUOTE=Fleskhjerta;34999121]Also it seems like the LookAt() function is buggy.
[CODE]hook.Add("render.gameoverlay","OnRender",function()
closest = ents.GetClosestToEntity(LocalPlayer())
LocalPlayer():LookAt(closest)
end)
[/CODE]
I spawned a pig close to me but it justs looks at the horizon of the map.[/QUOTE]
It seems like LookAt is bugged, we will have a look at it :heh:
[QUOTE=subenji99;35004934]now I'm not claiming to know how LookAt is supposed to work, but aren't you telling the LocalPlayer to look at an entity there?
you probably want:
[lua]closest:LookAt(LocalPlayer())[/lua][/QUOTE]
No, i want the player to look at the closest animal/mob, and even with your code, the closest animal/mob looks at the horizon of the map
I'm pretty sure LookAt won't work on players. The players head angle is based on where you are actually looking.
LuaCraft is now running at v1.2+ :v:
Once you launch the client you will be asked to update (as usual) and the server will be published later today.
Happy crafting guys!
[QUOTE=LuaStoned;35121941]LuaCraft is now running at v1.2+ :v:
Once you launch the client you will be asked to update (as usual) and the server will be published later today.
Happy crafting guys![/QUOTE]
Still no response on whether there's a JSON library exposed to lua :v:
[QUOTE=Elspin;35123459]Still no response on whether there's a JSON library exposed to lua :v:[/QUOTE]
[url]http://luaforge.net/projects/json/[/url]
[QUOTE=thomasfn;35123705][url]http://luaforge.net/projects/json/[/url][/QUOTE]
I tried several libraries, that one was the only one that worked - but the JSON it produces was awful and unreadable, and a few websites claimed it wasn't valid JSON anyways.
EDIT: oh, and it preserved numeric values but not keys, which were turned into strings.
[QUOTE=Elspin;35123459]Still no response on whether there's a JSON library exposed to lua :v:[/QUOTE]
We will expose it as soon as the server gets updated to 1.2 (this night / tomorrow).
[QUOTE=LuaStoned;35125600]We will expose it as soon as the server gets updated to 1.2 (this night / tomorrow).[/QUOTE]
Excellent news to go with some excellent news then!
Made a json encoder.
[lua]local tblTest = {
1,
["dix"] = {
"a",
"bee",
1337,
{
1,
2,
3,
4,
},
true,
false,
},
false,
true,
1337.1337,
}
print( json.Encode( tblTest ) )[/lua]
Will output
[code]{
"3": true,
"2": false,
"1": 1,
"4": 1337.1337,
"dix": [
"a",
"bee",
1337,
[
1,
2,
3,
4
],
true,
false
]
}[/code]
Still trying to figure out how to go about making the decoder work with a lua table properly.
[editline]13th March 2012[/editline]
Got decoding working.
json.txt
[code]{
"mysql":{
"hostname":"localhost",
"username":"root",
"password":"thisisntarealpassword",
"database":"srcds_db",
"portnum":3306,
"unixsock":"\/var\/run\/mysqld\/mysqld.sock"
},
"servers":{
"terrortown":{
"ipaddress":"64.31.29.61:27015",
"hostname":"ttt.breakpointservers.com"
},
"bhop":{
"ipaddress":"64.31.63.213:27015",
"hostname":"bhop.breakpointservers.com"
},
"deathrun":{
"ipaddress":"64.31.63.210:27015",
"hostname":"deathrun.breakpointservers.com"
},
"climb":{
"ipaddress":"64.31.29.59:27015",
"hostname":"climb.breakpointservers.com"
}
}
}[/code]
[lua]table.Print( json.Decode( file.Read( "data/json.txt" ) ) )[/lua]
Output
[code]servers
bhop
ipaddress = 64.31.63.213:27015
hostname = bhop.breakpointservers.com
climb
ipaddress = 64.31.29.59:27015
hostname = climb.breakpointservers.com
deathrun
ipaddress = 64.31.63.210:27015
hostname = deathrun.breakpointservers.com
terrortown
ipaddress = 64.31.29.61:27015
hostname = ttt.breakpointservers.com
mysql
username = root
portnum = 3306
hostname = localhost
database = srcds_db
password = thisisntarealpassword
unixsock = /var/run/mysqld/mysqld.sock[/code]
Nice, that's a very readable JSON output. Not the biggest deal but does it preserve numeric keys/values or do they get turned into strings?
Values should preserve there value type during conversions. Keys will be turned into strings, [del]but I don't think that should cause any issues when it comes to numbers.
Indexing [1] is the same as indexing ["1"][/del]
[QUOTE=BlackAwps;35130238]Values should preserve there value type during conversions. Keys will be turned into strings, but I don't think that should cause any issues when it comes to numbers.
Indexing [1] is the same as indexing ["1"][/QUOTE]
Are you sure about that? I just tried the following:
[code]local test = {}
test["1"] = "Testing"
print( test[1] )[/code]
and it produced "nil" in the log.
Odd, figured it would work because you can do stuff like this.
[lua]print( "1" * 3 )[/lua]
[QUOTE=BlackAwps;35130539]Odd, figured it would work because you can do stuff like this.
[lua]print( "1" * 3 )[/lua][/QUOTE]
That ones makes more sense. As the multiplcation operator shouldn't work on a string really, it can detect a string datatype and convert it into a number. Keys can of course be strings though, so you can't really do the same thing
Well, I made it so it you can index numbers as strings. Think this will cause any problems for anyone? :v:
[lua]
local testTbl = { ["1"] = "ABC123" }
print( testTbl[1] )
ABC123
local testTbl = { [1] = "ABC123" }
print( testTbl["1"] )
ABC123
[/lua]
[QUOTE=BlackAwps;35130712]Well, I made it so it you can index numbers as strings. Think this will cause any problems for anyone? :v:
[lua]
local testTbl = { ["1"] = "ABC123" }
print( testTbl[1] )
ABC123
local testTbl = { [1] = "ABC123" }
print( testTbl["1"] )
ABC123
[/lua][/QUOTE]
Well, if you're going to do it you might as well do it before you build up a userbase that does things like having tables full of both string number keys and number keys. Not sure how good of an idea that is though, how exactly are you doing it?
Well, in LuaJava, when doing a rawset/get it checks if the value is a true integer and not a string integer like my "1" * 3 example. I just changed it to check if it was a possible integer instead of strictly checking if it was a true integer. :v:
We will test this and revert changes if needed..
The server is on 1.2 now, lets hope everything works :v:
After several hours of royal pain in the butt, I present you the new console:
[img]http://img.luastoned.com/luacraft_console_v3.png[/img]
[img]http://img.luastoned.com/luacraft_console_v4.png[/img]
Happy crafting!
BlackAwps, I'm not sure if this was intentional but if you only have a certain amount of keys, the entire JSON string is put onto one line.
Aside from that, numeric keys are not preserved - ie if you set a key to 0, it will be 1 when decoded. As you've made it so that index[1] is equal to index["1"], you also can't convert numeric keys to string keys to preserve their order as it will just think it's a numeric key.
EDIT: Unrelated to JSON issues but if your position is set to a great distance away by the server using SetPos, it will kick you with the moved too fast error.
[QUOTE=Elspin;35169841]..
EDIT: Unrelated to JSON issues but if your position is set to a great distance away by the server using SetPos, it will kick you with the moved too fast error.[/QUOTE]
I see, we have had this problem before once. I know howto fix it, lets see if MCP updated the function name already.
[QUOTE=Elspin;35169841]BlackAwps, I'm not sure if this was intentional but if you only have a certain amount of keys, the entire JSON string is put onto one line. [/QUOTE]
Mind posting some code that I can use to replicate it? Also, as a side note, json.Encode accepts a second argument as a number. It will be the number of spaces it uses to indent the encoded string, which defaults to 4 if nothing is passed. I'm guessing this may have something to do with your issue.
[QUOTE=Elspin;35169841]Aside from that, numeric keys are not preserved - ie if you set a key to 0, it will be 1 when decoded. As you've made it so that index[1] is equal to index["1"], you also can't convert numeric keys to string keys to preserve their order as it will just think it's a numeric key.[/QUOTE]
I will probably revert the changes to the indexing, seems to cause more problems than it solves.
Also, I think I fixed this.
[lua]local enc = json.Encode( { [-1]=false,[0]="purple",[1]=1.337, } )
print( enc )
local dec = json.Decode( enc )
table.Print( dec )[/lua]
[code]{
"1": 1.337,
"0": "purple",
"-1": false
}
1 = 1.337
0 = purple
-1 = false[/code]
[QUOTE=BlackAwps;35180787]Mind posting some code that I can use to replicate it? Also, as a side note, json.Encode accepts a second argument as a number. It will be the number of spaces it uses to indent the encoded string, which defaults to 4 if nothing is passed. I'm guessing this may have something to do with your issue.[/QUOTE]
It's not that it's not indenting it enough, it's that it's not indenting it at all. Some example output is here, the home file for our server:
[code]
{
"epaulepp": {
"overworld": "-235.08103438105024,100.0,112.26332330855735",
"endworld": "99.44148277300152,49.0,1.7783805922070617",
"nether": "194.116975555491,65.0,-64.97782159787346"
},
"ashigaru7": {"overworld": "626.0697296857445,66.0,1121.1052450177972"},
"Weedragonslayer": {"overworld": "490.3979184202929,87.0,-325.343141961538"},
"Balimbanana": {
"overworld": "203.90625,25.0,123.5",
"nether": "42.92440847200222,51.0,14.994434759316356"
},
"Narkvic": {"overworld": "-35.65284134560561,64.0,57.9137702542554"},
"charliemanboy": {"overworld": "322.09375,72.0,-458.875"},
"Adrian383": {"overworld": "391.69999998807907,111.0,-197.07445852790516"},
"Jackle15": {"overworld": "426.1845855098571,85.0,-285.91814087474296"},
"Elspin": {"overworld": "490.53723,-426.9176,75"},
"andrewman123": {"overworld": "414.34560230975666,71.0,-15.907128261796156"}
}
[/code]
Basically any table with only one key is put into one line - and this may be intentional like I said, but it makes adding keys in manually a bit annoying for large tables. This should be able to reproduce it:
[code]
tbl = {}
tbl["test"] = 5
print( json.Encode( test ) )
[/code]
As a side note, this is really some great work - we're officially switching all of our server files as you can probably see from above to luacraft and I'll probably post the recreated bukkit plugins on the luacraft forums once they're proven to work.
Ah ok, so it's just not indenting single keys. I'll see what I can do.
[editline]17th March 2012[/editline]
Fixed
Sorry, you need to Log In to post a reply to this thread.