Hi, me here
Some of my users are asking to make a support for the XQM coaster tracks.
They are defined as a table with records, that i call my RailDB.
I currently got 47 items in my Panel, of which 2 are XQM tracks.
It seems like i can't get the values from the records defined as followed:
[code]
["models/XQM/CoasterTrack/bank_turn_90_4.mdl"] = {
Name = "Track Turn 90 Up",
Type = "Coaster",
Offsets = {
[0] = {
P = Vector(292.800,60.724, 1.436),
O = Vector(292.800,60.724, 1.436),
F = Vector(1, 0,0),
U = Vector(0,-1,1)
},
[1] = {
P = Vector(-475.323,-707.923,1.439),
O = Vector(-475.323,-707.923,1.439),
F = Vector(0,1,0),
U = Vector(1,0,1)
}
}
},
["models/XQM/CoasterTrack/slope_225_1.mdl"] = {
Name = "Track 225 Up",
Type = "Coaster",
Offsets = {
[0] = {
P = Vector(76.000,0, -7.300),
O = Vector(76.000,0, -7.300),
F = Vector(1,0,0),
U = Vector(0,0,1)
},
[1] = {
P = Vector(-72.628,0, 22.045),
O = Vector(-72.628,0, 22.045),
F = Vector(-0.92387920618057,4.4096889695311e-008,0.38268420100212),
U = Vector(0.33539098501205,-3.1563570270144e-031,0.94207900762558)
}
}
}
[/code]
I read that one LUA file has limits of variables/functions, and my DB has to be actually in another file.
Is that really true, and how can i properly add the XQM tracks.
[code]
RailDB["models/XQM/CoasterTrack/slope_225_1.mdl"].Type
[/code]
For example returns empty string ...
Addon link: [url]http://steamcommunity.com/sharedfiles/filedetails/?id=287012681[/url] ( 1931 lines of code )
Lua, not LUA.
[QUOTE=HumbleTH;45527287]Lua, not LUA.[/QUOTE]
When you can code, you can criticize others.
As I am unable to test your code right now, could you post EXACTLY how you are getting the values out of the table? If it is how you say it is, I have never seen anyone with this kind of problem.
Based on the key, I am getting my track definition record.
Record = RailDB["string_model_path"]
I got a GetType function:
[code]
function GetTypeByModel(Model)
local Type = "" -- Empty string
if(RailDB[Model]) then -- If existing record
Type = RailDB[Model].Type -- Get it Duhh 6_6
end
return Type
end
[/code]
RailDB is a global table of rail definitions with exact structure as above ....
I am also considering of relocating my DB into a text file, because of that, but it will be rather slow ( HDD Access ).
Can I use Lua I/O file functions for that:
[code]
function GetRailDBInfo(sModel)
local f = io.open("rail_definitions.db", "r")
io.input(f)
io.close(f)
end
[/code]
Regards !
You could use the file library.
But I think it'd be better to use SQLite for the database instead of text files because you can do almost instantaneous lookups with little load, if done correctly.
Although, I still think it'd be easier to use tables, that is if you can get them working.
Also, a heads up if you decide to use SQL though PData or Queries, if you write a table to SQL it will only write the pointer to the table not the table itself. You will need to encode it in JSON or similar to get effective storage.
When the table does not return the correct value, print the key being used. I am 99% sure it's the input that isn't correct.
But ... how can make a DB inside the tool.
Like if the tool first initializes... store the rails data into the DB
(in the ram will be awesome just one time) ...
Then with something like:
Indexed by model ( string )
SELECT type, name
INTO sType, sName
FROM RailDB
WHERE model = 'models/XQM/CoasterTrack/bank_turn_90_4.mdl'
For example....
And where should i store it ( where does this store itself ) anyway using the SQLLite:
CREATE TABLE RailDB ...... insite the tool's code ...
This sounds promising .... [url]http://wiki.garrysmod.com/page/sql/Query[/url]
P.S. Don't judge me Oracle is awesome !
[editline]29th July 2014[/editline]
[QUOTE=dingusnin;45533083]When the table does not return the correct value, print the key being used. I am 99% sure it's the input that isn't correct.[/QUOTE]
No, in my case i am using the model as a key and if I call:
[code]
print("Table["..k.."] = "..RailDB[k].Type)
[/code]
Prints:
[code]
Table[models/XQM/CoasterTrack/bank_turn_90_4.mdl] = -- It ends here with an
-- empty string instead
-- of "Coaster"
[/code]
Is the key too long?
[QUOTE=dvd_video;45533148]
[code]
Table[models/XQM/CoasterTrack/bank_turn_90_4.mdl] = -- It ends here with an
-- empty string instead
-- of "Coaster"
[/code][/QUOTE]
It would error if there the 'Type' key-value wasn't set, it would error because you would be trying to concatenate a nil value. Check if the type in that entry isn't empty.
[QUOTE=dingusnin;45534867]It would error if there the 'Type' key-value wasn't set, it would error because you would be trying to concatenate a nil value. Check if the type in that entry isn't empty.[/QUOTE]
But ... it shouldn't . Also i am not getting errors, just [b]empty string[/b].
[code]
["models/XQM/CoasterTrack/bank_turn_90_4.mdl"] = {
Name = "Track Turn 90 Up",
Type = "Coaster", -- See right here !
Offsets = {
[0] = {
P = Vector(292.800,60.724, 1.436),
O = Vector(292.800,60.724, 1.436),
F = Vector(1, 0,0),
U = Vector(0,-1,1)
},
[1] = {
P = Vector(-475.323,-707.923,1.439),
O = Vector(-475.323,-707.923,1.439),
F = Vector(0,1,0),
U = Vector(1,0,1)
}
}
}
[/code]
Anyways, there is possible mod for that
to rid of all unnesesary objects like so:
Rec = RailDB["models/XQM/CoasterTrack/bank_turn_90_4.mdl"];
1) Get rid of F,U and replace them with an angle ( Rec.Offsets.A ).
2) If A is null then the angle is [code] Angle(0,0,0) [/code]
3) If P is null then the active point offset position
will be where the origin is
[code]
ActivePointPos:Set(Rec.Offsets.O)
ActivePointPos:Rotate(trEnt:GetAngles())
ActivePointPos:Add(trEnt:GetPos())
[/code]
How that sounds to you.. Less things to calc..
Its not the size of the table, its the key, perhaps the capital letters in the model path
As this [b] "models/sprops/trans/train/track_h03.mdl" [/b] is OK, however this [b] "models/XQM/CoasterTrack/slope_225_1.mdl" [/b] is not.
Not only that, but Gmod crashes also :/
Send me the lua file, I'll look into it.
[QUOTE=dingusnin;45548640]Send me the lua file, I'll look into it.[/QUOTE]
Skype, Dropbox, Mega I will soon stop using Skype though ...
Also ASAIGH I will try using only the file name as a key like so:
[code]
M1 = "models/sprops/trans/train/track_h03.mdl"
function Model2Key(sModel)
local Len = string.len(sModel)-4
local Cnt = Len
while(Cnt > 0) do
Ch = string.sub(sModel,Cnt,Cnt)
if(Ch == '/') then
break
end
Cnt = Cnt - 1
end
return string.sub(sModel,Cnt+1,Len)
end
print(Model2Key(M1))
[/code]
Console: [b] track_h03 [/b] as there are no slashes and capital letters...
I am now using an angle instead of two vectors ( One object for 3 directions = less Memory XD)
The key has to be RELATED TO THE MODEL because otherwise if I add more rails, there will be searching ( for keys like so 1,2,3,4 ....)
and the preformance will drop exponentialy. Why ... because I am using this main master function where the magic happens in every piece of the code, that's why its so easy to maintain this - only one place to change stuff.
[code]
--[[
* trEnt = Trece.Entity
* trHitPos = Trece.HitPos
* sHoldModel = Node:DoClick() --> Node:Model()
* nHoldPointID = nIncDecID(nHoldPointID,....) per Right click ...
* nActRadius = Min radius to get an active point from client
* ucsPos = Manual Pos offset
* ucsAng = Manual Ang offset
]]--
function stGetRailModelSpawnData(trEnt,trHitPos,sHoldModel,
nHoldPointID,nActRadius,
ucsPos,ucsAng)
[/code]
[code]
RailsDB["track_h03"].Type is a hell of a lot better way to to all this.
[/code]
Hi tested the key today, you will be amazed it woks !
Using: Lua 5.2.3 Copyright (C) 1994-2013 Lua.org, PUC-Rio
Compiled From LUA Org
[code]
---- Simple vector closeur
local function Vector(x,y,z)
self = {
X = x or 0,
Y = y or 0,
Z = z or 0,
mt = {}
}
setmetatable(self,self.mt)
function self:Add(V)
self.X = self.X + V.X
self.Y = self.Y + V.Y
self.Z = self.Z + V.Z
end
function self:Sub(V)
self.X = self.X - V.X
self.Y = self.Y - V.Y
self.Z = self.Z - V.Z
end
function self:Print(V)
print("Vec("..tostring(self.X)..", "
..tostring(self.Y)..", "
..tostring(self.Z)..") ")
end
self.mt.__add = function(V1,V2)
return Vector(V1.X + V2.X,V1.Y + V2.Y,V1.Z + V2.Z)
end
self.mt.__sub = function(V1,V2)
return Vector(V1.X - V2.X,V1.Y - V2.Y,V1.Z - V2.Z)
end
self.mt.__mul = function(A,B)
if(type(B) == "number") then
return Vector(B*A.X, B*A.Y, B*A.Z)
else
return Vector(B.X*A, B.Y*A, B.Z*A)
end
end
self.mt.__div = function(A,B)
return Vector(A.X/B, A.Y/B, A.Z/B)
end
return self
end
M1 = "models/sprops/trans/train/track_h03.mdl"
M2 = "models/XQM/CoasterTrack/slope_225_1.mdl"
local RailsDB = {
[M1] = {
Type = "Regular",
Offsets = {
[0] = {
F = Vector(4,4,4),
U = Vector(2,2,2)
}
}
},
[M2] = {
Type = "Coaster",
Offsets = {
[0] = {
F = Vector(1,1,2),
U = Vector(2,2,3)
}
}
}
}
print(Model2Key(M1))
print(Model2Key(M2))
print(RailsDB[M1].Type)
RailsDB[M1].Offsets[0].F:Print()
RailsDB[M1].Offsets[0].U:Print()
print(RailsDB[M2].Type)
RailsDB[M2].Offsets[0].F:Print()
RailsDB[M2].Offsets[0].U:Print()
local V = (RailsDB[M2].Offsets[0].F + RailsDB[M2].Offsets[0].U)
V:Print()
----- Result in Console
Vec(6, 6, 6)
Vec(12, 12, 12)
Vec(12, 12, 12)
Vec(1, 1, 1)
track_h03
slope_225_1
Regular
Vec(4, 4, 4)
Vec(2, 2, 2)
Coaster
Vec(1, 1, 2)
Vec(2, 2, 3)
Vec(3, 3, 5)
[/code]
It was the key RailsDB["track_h03"].Type for the win !
It WORKS !
[url]https://mega.co.nz/#!bc1kESDK!3OA-Lvr3onEQ9fDMTYxd45DKZSKJ6qaHMs3asLKqFcM[/url]
[url=http://postimg.org/image/e7ayhhd3v/][img]http://s1.postimg.org/e7ayhhd3v/2014_07_31_00001.jpg[/img][/url]
Why i won't do the PHX switchers, but my code supports them !
[url=http://postimg.org/image/qkj7andej/][img]http://s1.postimg.org/qkj7andej/PHX_bug.jpg[/img][/url]
I still thin that SQL is a better option!
Sorry, you need to Log In to post a reply to this thread.