767 posts
Posted 03 October 2013 - 10:03 AM
Hello Everyone…
Im making a whole new game for CC, and im stuck….
I'm trying to make a variable be a variable in the same table like this:
local data = {
sys_path = ".newgame";
["user"] = {};
["server_path"] = {
path = sys_path.."/.newgameSERVER"; -- Line 15
};
};
Im getting error:
newgame:15: attempt to concatenate nil and string
Im confused…. I though it would be possible to do so? but then i cant..
Any help is appreciated
Thanks in Advance
8543 posts
Posted 03 October 2013 - 10:52 AM
Create your table with just sys_path in the declaration, then do this after the table declaration:
data.path = data.sys_path .. "whatever"
Also, I'm really hoping that this is a simplified example, since sys_path is a static string. You could also declare a local variable before your table and use that to set sys_path and concatenate to form the path variable.
767 posts
Posted 03 October 2013 - 11:14 AM
So only this?
local data = {
sys_path = ".newgame";
data.path = data.sys_path.."/.newgameSERVER";
};
Well if yes, then i have to tell you that im having 761 lines of code in this "data" table… (ingame stuffs)… so then i have to create a table for every 278 lines of paths?
Full code will be sent to Lyqyd only, cuz I know he wont make it publish, as he is Admin…
1522 posts
Location
The Netherlands
Posted 03 October 2013 - 11:19 AM
If you are accessing a table variable, there is no exception in calling them. If you call a table variable (aka key), then you always have to do:
TABLENAME.key
--# Your case:
data.sys_path
767 posts
Posted 03 October 2013 - 11:39 AM
Well then what if i'm going to do this:
local sys = {
system_path = ".newgame";
};
data = {
start_balance = 4000;
["user"] = {};
["server_path"] = {
path = sys.system_path.."/.newgameSERVER"; -- newgame-server-path is equal to data["server_path"].path
};
["agent_path"] = {
path = sys.system_path.."/.newgameDATABASE"; -- newgame-agent-path is equal to data["agent_path"].path
};
["softwareTools"] = {
["v1.0"] = {
["newgametool"] = {
path = data["server_path"].path.."/v1.0/tool.exe"; -- NOTE THIS LINE
-- and btw all closings are correctly made... in the full code...
758 posts
Location
Budapest, Hungary
Posted 03 October 2013 - 01:22 PM
Here…
-snip-
…You did this:…
You could also declare a local variable before your table and use that to set sys_path and concatenate to form the path variable.
…In a very overcomplicated way.
767 posts
Posted 03 October 2013 - 01:55 PM
Im so confused right now…. uurgh!
Do i need the system_path variable IN the data table?
1522 posts
Location
The Netherlands
Posted 03 October 2013 - 02:09 PM
Just put:
local system_path = ""
local data = {
something = system_path .. ""
}
It cannot get any harder :P/>
767 posts
Posted 03 October 2013 - 02:17 PM
I dont think you understand this….
In my previous post (
Well then what if i'm going to do this:
local sys = {
system_path = ".newgame";
};
data = {
start_balance = 4000;
["user"] = {};
["server_path"] = {
path = sys.system_path.."/.newgameSERVER"; -- newgame-server-path is equal to data["server_path"].path
};
["agent_path"] = {
path = sys.system_path.."/.newgameDATABASE"; -- newgame-agent-path is equal to data["agent_path"].path
};
["softwareTools"] = {
["v1.0"] = {
["newgametool"] = {
path = data["server_path"].path.."/v1.0/tool.exe"; -- NOTE THIS LINE
-- and btw all closings are correctly made... in the full code...
)
Then I wanted you to note that line….
I changed the whole code to:
http://pastebin.com/vc1p3J3zbut im getting errors at line 41 … (concatenate nil and string)
Wait…. Just forget it… I think i wont get the answer i wanted, here.. so im just gonna quit this post for now….
8543 posts
Posted 03 October 2013 - 02:40 PM
I haven't read through the full code yet, but my suggestion for changing your original code would look like this:
local data = {
sys_path = ".newgame",
user = {}
}
data.server_path = {
path = data.sys_path.."/.newgameSERVER"; -- Line 15
}
Note that all I did was move the server path entry to be outside the original table declaration, so that it could reference things in the table.
767 posts
Posted 03 October 2013 - 02:42 PM
Well… How would the "path = data.server_path" then work, if that is called withing the data table?
(that is shown in the full code at line 41) And btw… just to know… What does "Multiple points mean" ? does it mean that i have two tables called the same?, because in the "ips" table, it errors with this kinda thing ( i tried commenting the ips table, and found out that the ips function is kinda carrying some kinda thing thats called the same as another "thing") do you know why?
8543 posts
Posted 03 October 2013 - 02:50 PM
In the full code, you're declaring server_path before the table, not inside it like in your example code! There's no problem on that line with that concatenation in the full code.
If that isn't what you're asking, please rephrase the question.
767 posts
Posted 03 October 2013 - 02:55 PM
Hmm.. You're right… I just forgot to reload the program (derp)
But another question (might be a bit hard to answer)
Well… When i "uncomment" the whole "ips" table, which is filled with tables, filled with "ip = an ip address" and "defaultinmenu = bolean" and a "highlighted = bolean" variable… Then when running the program it tells me that there's "multiple points"… which i dont understand why… is it because there is a "global" "ip" variable in every single "ip-name" table?
EDIT: Hmm.. I somehow think that we should've done this convesation over the private chat instead, because you are the only one knowing the full code?
Edited on 03 October 2013 - 12:56 PM
8543 posts
Posted 03 October 2013 - 02:58 PM
Make them strings. You can't have numbers with multiple decimal points in them. Since you don't have quotes, it thinks you're declaring them as numbers.
767 posts
Posted 03 October 2013 - 03:01 PM
ahhh… Okay…
Thanks ;)/>
*solved post*
167 posts
Posted 03 October 2013 - 11:39 PM
If i'm not mistaken, the key in a table can be written as
["myKey"] = ...
or simply,
myKey = ...
unless you're specifically inserting a key with a dynamic string (user input perhaps) it's easier to write the second example.