Jump to content




Help with train station project


46 replies to this topic

#41 pietro.devo

  • Members
  • 25 posts

Posted 15 February 2016 - 11:42 AM

101 was the key for sub-table, value was "free".
Now I tryed using a different name for file, just using the name "file".
This seems to solve the problem but actually what is wrong is the table: First boot I always let computer gets some states updated to fill the table, then I reboot it and next time I ask for a state or I try to add another update it stops executing code beacuse of attempt to call a nil value, so seems like not only the previously saved table is not loaded correctly with old values (deduction from the state request command), but simply It can't push again values in it and fill table, meaning it doesn't exists and is considered nil (deduction from the state update command)

Edited by pietro.devo, 15 February 2016 - 12:11 PM.


#42 pietro.devo

  • Members
  • 25 posts

Posted 04 March 2016 - 03:56 PM

I have started changing all my rednet stuff to tables, from now no more strings and such things.
I really understand the power and simplicity of using tables. What I am at same time doing is remove completely the need of configuring tons of computers on the base of each different station making a cntralized config computer that just instructs every other at each boot, so when I need to change something, add a schedule, change a platform and so on, I simply change the config in it and it is all done.

Next step will be also putting away functions from local systems and having them called too.

Here is the code, while still working on it I am keeping in my language, sorry for this, at the end will be translated:

Spoiler

So basically here I set up all the stuff in specific tables, then I just call the table with instructions I really need for every manager computer, for example the scheduling one won't need to know informations about switches and lights and won't ask for these tables and so on.

Here the routes manager posted before, without local configs and with use of tables for every command:

Spoiler

I have rednet displayer that show me when this route manager boot up asks correctly for instruction tables and the config manager gives them to it, so at this point no problems, what is not working is that whatever command I try to send the programs doesn't seem to respond, what is wrong?

Edited by pietro.devo, 04 March 2016 - 04:01 PM.


#43 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 05 March 2016 - 08:41 AM

View Postpietro.devo, on 04 March 2016 - 03:56 PM, said:

I have rednet displayer that show me when this route manager boot up asks correctly for instruction tables and the config manager gives them to it, so at this point no problems, what is not working is that whatever command I try to send the programs doesn't seem to respond, what is wrong?

Urgh...

I see two great long sheets of code with rednet calls in them. Could you please pastebin them and clearly indicate which one isn't working as expected, and the line numbers which should be doing whatever isn't being done?

#44 pietro.devo

  • Members
  • 25 posts

Posted 05 March 2016 - 11:55 AM

Let's say I just try the shutdown command on gestore_tragitti.
I execute this translated:

rednet.broadcast({"systems","routes","manager","shutdown"})

On the other end, routes manager should shutdown itself beacuse of this:

[...]

while true do
local id, code = rednet.receive()

[...]

if code == {"systems","routes","manager","shutdown"} then
rednet.broadcast({"shutdown","routes","manager"})
os.shutdown()
end

[..]

end

I imagine there is something very stupid I am doing here, but can't figure out

Edited by pietro.devo, 05 March 2016 - 11:58 AM.


#45 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 05 March 2016 - 01:15 PM

You can't compare tables like that.
print( {} == {} ) --#output: false

Edited by KingofGamesYami, 05 March 2016 - 01:15 PM.


#46 pietro.devo

  • Members
  • 25 posts

Posted 05 March 2016 - 04:36 PM

Ok, so eventually I can also create a loop to verify the matching of every entry of table, correct?

Edited by pietro.devo, 05 March 2016 - 05:42 PM.


#47 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 05 March 2016 - 07:19 PM

Yes. It'd be something like this:
local function comparetables( a, b )
  if #a ~= #b then
    return false
  end
  for k, v in pairs( a ) do
    if b[ k ] ~= v then
      return false
    end
  end
  return true
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users