Time |
Nick |
Message |
01:47 |
|
VanessaE joined #minetest-mods |
01:53 |
|
VanessaE joined #minetest-mods |
02:48 |
|
VanessaE joined #minetest-mods |
02:52 |
|
VanessaE joined #minetest-mods |
14:59 |
|
PilzAdam joined #minetest-mods |
16:27 |
|
Jordach joined #minetest-mods |
16:27 |
|
Jordach joined #minetest-mods |
17:04 |
|
rubenwardy joined #minetest-mods |
17:31 |
|
Traxie21_ joined #minetest-mods |
17:31 |
Traxie21_ |
Does anyone here know how to use file.io very well? Or another way to store persistant data for a time? |
17:31 |
PilzAdam |
yep |
17:32 |
Traxie21_ |
Can you give me a quick run-through? |
17:32 |
Traxie21_ |
I'm not too good with lua :3 |
17:32 |
PilzAdam |
what do you want to save? |
17:33 |
Traxie21_ |
basicly, [1stname][2ndname][time] |
17:33 |
Traxie21_ |
but it has to store more than one value of that, and delete it after about 30 seconds |
17:33 |
Traxie21_ |
I'm making a sorely needed messaging mod |
17:34 |
PilzAdam |
general reference: http://www.lua.org/pil/21.html |
17:34 |
PilzAdam |
https://github.com/PilzAdam/beds/blob/master/init.lua#L145 |
17:34 |
PilzAdam |
this is from my beds mod |
17:34 |
PilzAdam |
it saves the beds_player_spawns table in a file |
17:35 |
PilzAdam |
here is the saving: https://github.com/PilzAdam/beds/blob/master/init.lua#L174 |
17:35 |
PilzAdam |
(the first link was reading) |
17:35 |
Traxie21_ |
I looked at the homes mod, but it didnt make much sense |
17:36 |
PilzAdam |
you basically do: local file = io.open("file", "w") |
17:36 |
PilzAdam |
then check for file: if file then |
17:36 |
Traxie21_ |
ok |
17:36 |
PilzAdam |
and then write your table into it: file:write(minetest.serialize(your_table)) |
17:36 |
PilzAdam |
file:close() |
17:37 |
Traxie21_ |
so this right? beds_player_spawns = minetest.deserialize(file:read("*all")) |
17:37 |
PilzAdam |
and to read it open it with io.open("file", "r") |
17:37 |
PilzAdam |
and local read_table = minetest.deserialize(file:read("*all")) |
17:37 |
Traxie21_ |
what line is that in your code? |
17:38 |
PilzAdam |
line 174 to178 is saving, and 145 to 150 is reading |
17:38 |
Traxie21_ |
k |
17:39 |
PilzAdam |
saving more than one table in a file is more complicated |
17:39 |
Traxie21_ |
hmm |
17:39 |
Traxie21_ |
dosn't your mod save one bed per player? |
17:40 |
PilzAdam |
my mod saves the spawn positon indexed by the name |
17:40 |
PilzAdam |
but the contents of the table are not relevant for saving |
17:41 |
Traxie21_ |
could you pastebin an example of a file created by beds? |
17:41 |
PilzAdam |
https://github.com/celeron55/minetest/blob/master/doc/lua_api.txt#L996 |
17:41 |
PilzAdam |
it looks like this |
17:43 |
PilzAdam |
files in this format are not well readable by humans |
17:43 |
Traxie21_ |
Wait, imma install your beds mod and start it up |
17:43 |
PilzAdam |
you have to sleep one night in the bed |
17:44 |
Traxie21_ |
k |
17:45 |
Traxie21_ |
brb |
17:47 |
Traxie21_ |
how does one get in a bed >_> |
17:48 |
PilzAdam |
rightclick (requires latest dev version of minetest) |
17:48 |
PilzAdam |
or use the 0 |
17:48 |
PilzAdam |
.4.4 version |
17:48 |
Traxie21_ |
I have 0.4.4 |
17:48 |
Traxie21_ |
ooh ok |
17:48 |
PilzAdam |
(see forum topic) |
17:49 |
Traxie21_ |
this game is working as hard as possible to make this take as long as possible >.< |
17:51 |
Traxie21_ |
erm |
17:51 |
Traxie21_ |
I slept 2 nights in the same bed |
17:51 |
Traxie21_ |
Where's the file? |
17:51 |
PilzAdam |
in your worl directory |
17:52 |
PilzAdam |
*world |
17:52 |
Traxie21_ |
Ah |
17:52 |
Traxie21_ |
TYVM |
17:52 |
Traxie21_ |
ok, it makes a bit more sense now |
17:53 |
PilzAdam |
here: https://gist.github.com/4540471 |
17:53 |
PilzAdam |
I made some quick helper functions |
17:53 |
PilzAdam |
(untested) |
17:54 |
PilzAdam |
it should help you understand the system |
17:55 |
Traxie21_ |
ok :D |
17:55 |
Traxie21_ |
I think i got the basics down, just wondering how one would put the param in the second value for write |
17:55 |
Traxie21_ |
messages_list[player:get_player_name()] = param() |
17:55 |
PilzAdam |
you can save every table like this |
17:55 |
Traxie21_ |
im only good with PHP :3 |
17:56 |
Traxie21_ |
Is the syntax for param right? |
17:56 |
PilzAdam |
Lua tables can more than the arrays of other languages |
17:56 |
PilzAdam |
depends on what param is |
17:57 |
Traxie21_ |
wait... how do I pass two params.... God, I know nothing |
17:57 |
PilzAdam |
what is do you want to save? |
17:57 |
PilzAdam |
-is |
17:57 |
Traxie21_ |
playername1, playername 2 |
17:58 |
PilzAdam |
then you can just create a table {playername1, playername2} and save it like this |
17:58 |
PilzAdam |
s/like this/with the system explained above/ |
17:59 |
Traxie21_ |
I could, but playername2 is a param, and playername 1 is get_player_name() |
17:59 |
PilzAdam |
can you show me some of your code? |
17:59 |
Traxie21_ |
I'm trying to do /msg [name] [message] |
18:00 |
Traxie21_ |
wait... why do I have to save both names.... |
18:01 |
PilzAdam |
like this? http://forum.minetest.net/viewtopic.php?id=2704 |
18:01 |
Traxie21_ |
http://pastebin.com/Rqgh6sHF |
18:01 |
Traxie21_ |
NUUUU |
18:01 |
Traxie21_ |
Someone beat me to it >:I |
18:01 |
PilzAdam |
there are like thousands of version of this command in the forum |
18:02 |
Traxie21_ |
:I |
18:02 |
Traxie21_ |
I dont look very far do I |
18:02 |
Traxie21_ |
is there a /tpa mod? |
18:02 |
PilzAdam |
what? |
18:04 |
Traxie21_ |
Teleport requests |
18:04 |
PilzAdam |
dunno |
18:04 |
Traxie21_ |
I was working on that, but ran into the file.io problem as well |
18:04 |
PilzAdam |
you dont have to save things like this in files |
18:05 |
Traxie21_ |
Is there a way to create persistant variables that can only be used by certian players? |
18:05 |
Traxie21_ |
Vanessa said she thought file.io was the only way |
18:05 |
PilzAdam |
VanessaE is wrong |
18:05 |
Traxie21_ |
Dun dun DUUUUNN |
18:06 |
Traxie21_ |
ill talk later, I gtg |
18:06 |
Traxie21_ |
thanks for your help |
18:06 |
PilzAdam |
np |
18:06 |
Traxie21_ |
One day I might be able to print hello world |
18:06 |
PilzAdam |
print("Hello Traxie21_") |
18:06 |
Traxie21_ |
I know, I was being sarcastic |
18:07 |
Traxie21_ |
I know very little about Lua syntax |
18:07 |
PilzAdam |
http://www.lua.org/pil/ |
18:09 |
* Traxie21_ |
will go find some time to read that :3 |
18:09 |
Traxie21_ |
bai |
18:09 |
Traxie21_ |
thanks again |
18:10 |
VanessaE |
er, I didn't say file.io was the only way to do what she wants. |
18:10 |
VanessaE |
I was it was "a" way. |
18:11 |
VanessaE |
(she? he? dunno) |
18:11 |
PilzAdam |
it |
18:11 |
VanessaE |
heh |
19:16 |
|
NakedFury joined #minetest-mods |
19:37 |
|
Traxie21 joined #minetest-mods |
19:37 |
Traxie21 |
hehe |
19:38 |
Traxie21 |
Wait |
19:38 |
Traxie21 |
WOOT |
19:38 |
Traxie21 |
Plitz, its writing the file properly now :D |
19:42 |
Traxie21 |
I could use some help figuring out how to read it properly though |
19:43 |
PilzAdam |
you dont need to write them to a file |
19:44 |
PilzAdam |
just save them in a varaible you declare outside any function in your script |
19:47 |
Traxie21 |
static var? |
19:47 |
PilzAdam |
Lua doesnt have static variables, you can see every variable that isnt declared in a function as "static" |
19:48 |
Traxie21 |
k |
19:48 |
Traxie21 |
the issue is, I have to have a variable for each player combination.... |
19:48 |
PilzAdam |
use a 2D table |
19:49 |
PilzAdam |
{{player1,player2}, {player1, player3}, ...} |
19:49 |
Traxie21 |
okok, im reading the PIL tutorial... you forced me to it with your fancy terminology XD |
19:50 |
PilzAdam |
I actually try to use a not Lua specific terminlogy (mixed with Java, C) |
19:50 |
PilzAdam |
gtg now; bye |
19:50 |
Traxie21 |
bai |
20:02 |
Traxie21 |
Is there anyone here who could tell me what I'm doing wrong in a bit of code? |
20:09 |
|
mauvebic joined #minetest-mods |
20:09 |
Jordach |
you can continue if you want |
20:10 |
|
Xenux joined #minetest-mods |
20:11 |
Traxie21 |
Jordach |
20:11 |
Jordach |
hm |
20:11 |
Traxie21 |
Could you help me find a syntax error? |
20:11 |
* Jordach |
doesnt know lua, but tries to help |
20:11 |
Traxie21 |
I'm stuck with a simple syntax error... |
20:11 |
Jordach |
look for the line where it occurs |
20:12 |
Traxie21 |
luac: prog.lua:23: unexpected symbol near '}' |
20:12 |
Traxie21 |
http://pastebin.com/Rqgh6sHF |
20:12 |
Traxie21 |
llooks like a quick fix, but I know almost no lua |
20:14 |
Jordach |
add a comma to the end of line 20 to look like this: tpr_list[param] = player, |
20:15 |
Jordach |
lua is an asshole if you dont add commas |
20:15 |
Traxie21 |
that didnt do it |
20:15 |
Jordach |
hmm |
20:15 |
Traxie21 |
Now it says that the comma was unaccepted |
20:15 |
Traxie21 |
Unexpected symbol near "end" on line 21 |
20:16 |
Jordach |
ehm |
20:18 |
Traxie21 |
imma try to make the code more readable by not using the same vars for different things XD |
20:27 |
Traxie21 |
asked for help on forums |