Robinlemon 0 Posted April 17, 2015 Share Posted April 17, 2015 a Quote Link to post Share on other sites
0 Solution Harkole 2 Posted April 18, 2015 Solution Share Posted April 18, 2015 Sleep is a wonderful thing! - The answer to your question is Concatantaion, in Lua it is very simple to do here is an example: local word = "a string of text" local num = 5 print(word..num) -- to have fixed text just do print("This is always the same text, with the number stored in num "..num) Because when I first saw this post I was half asleep and not paying attention below this line, in the spoiler, is a semi solution. To see my original post with a full example of what I'd try to do for you issue click the spoiler button - if you want the challenge of doing it your self (always more rewarding) then don't! Not sure what the question is but based on the Wiki you forgot to open the port to broadcast on: -- Hook components -- (the Wiki has the event too but that is for the message receive part so i dropped it) local component = require("component") local m = component.modem -- get primary modem component local time = 5 -- time to wait between ping messages local count = 1 -- intialise count to 1 -- Open the port on the network and print out if it is open (should print true or this wont work) m.open(123) print(m.isOpen(123)) -- true -- Do a ping test (sort of) while count < 5 do m.broadcast(321, "ping "..count) count = count + 1 os.sleep(time) end -- close the network port m.close() Your receiving server will just simply listen with the event system... I don't really know why you'd want to do this but it's what you asked. -- Hook the Events library local event = require ("event") -- Wait for a message from another network card. local _, _, from, port, _, message = event.pull("modem_message") local data = tostring(message) -- check that the received event was a ping message, like ping 1 and do something if(data == "ping 1") then print "I received a ping, it was the first ping!" end Not tested this and it's currently 01:15 local time so I'm heading to bed, but hope this helps. Quote Link to post Share on other sites
0 Robinlemon 0 Posted April 18, 2015 Author Share Posted April 18, 2015 a Quote Link to post Share on other sites
0 Robinlemon 0 Posted April 18, 2015 Author Share Posted April 18, 2015 a Quote Link to post Share on other sites
0 Harkole 2 Posted April 19, 2015 Share Posted April 19, 2015 It's all about scope, or better memory management. If you are only doing a small program it doesn't matter but good practice is important. Lua code runs in blocks, local variables are only available in the current block, a global variable is always available. What this means in terms of memory is a global variable, once created will sit around in memory until the program ends or you set the variable to nil. The Lua manual explains this with examples but I am posting from my phone so don't have access to the link at the moment. Here is the link to what I am explaining: http://www.lua.org/pil/4.2.html Quote Link to post Share on other sites
0 dgelessus 26 Posted April 19, 2015 Share Posted April 19, 2015 It's not just a memory thing - though memory is a much bigger concern on OpenComputers than on a real computer - using global variables for everything clutters the global namespace and can cause odd bugs if you use the same name in different places. Because every computer has a single global namespace for every script (unless the script is called using pcall, which gives it an own "global" namespace) this means that a global variable from an external library can "leak" into your program, or even into other libraries. Quote Link to post Share on other sites
a
Link to post
Share on other sites