[Railcraft Mod] Elevator Control
#101
Posted 14 September 2013 - 12:10 AM
I'm afraid I'm away this weekend so you'll have to hang on a bit longer.
#102
Posted 17 September 2013 - 05:15 PM
Here is a clip of what i created so far
Its created with a client-server program,
The client code: http://pastebin.com/GRxRhE4X
The server code: http://pastebin.com/8E9CFEch
This are my first lua script i ever have created. So yes, i guess that the code is pretty messy, but seems to work well so far.
But there are still a lot of work to do
#103
Posted 17 September 2013 - 06:53 PM
I admire your lack of efficiency
I notice you have a space character between explodeChar and y. If you make your explodeChar \031 then that won't be necessary.
Interesting that you went for a client-server architecture. Have you thought about what to do when you have too many floors for just one server? Or multiplayer?
Once I've got this next release published I'm going to add a sort of server element - It'll still be peer to peer but one or more peers will dynamically take on the job of coordinating and relaying messages as required by the range.
What is your experience of programming?
#104
Posted 18 September 2013 - 04:10 AM
Away to detect where the minecart is and maybe a screen for the server to display the whole setup, and ofc a more beautiful GUI
Hehe thanks
But I got one problem, if I turn on 4 clients and not the server, the whole computercraft are getting slow :S
Client code:
local keepRunning = true;
while (keepRunning) do
rednet.broadcast("who")
senderId, message, distance = rednet.receive(5)
if (message == "server") then
keepRunning = false
end
end
I’m sure it’s because of this loop but I not sure why :S
The reason for the space between y and the explodechar is that i had a lot of problems with splitting the string when the messages was received from rednet.
I guess its this line you talking about (from client): rednet.send(senderId,"add " .. explodeChar .. " " .. y .. explodeChar .. computerID .. explodeChar .. n)
At start the line looked like: rednet.send(senderId,"add " .. y .. explodeChar .. computerID .. explodeChar .. n)
but i couldn’t split the string, and thought that it was because the char was different when it was received from rednet (the explode char was # at start)
So i changed the line so the client could tell the server about what char the server need to split the string with
But now I’m keeping it this way so the explode char can be different on server and client
What is the limit of floors? Is the limit based on the distance from each other when using wireless – Haven’t thought about multiplayer, thanks for remind me :/
Think I’m going to handle this with just add an option to auto detect or manual input of server ID, and turn off the auto detect on the server, so it won’t respond or new clients
The reason I created server/client setup is that I love to have only one that handle all communication and knowledge of the whole setup.
If the distance is becoming a problem I will make a gateway that only is used for forwarding the messages.
That’s sounds really cool, I’m looking forward to see your code for that
I have been programming in C# in about 12 years now I think, and been working as a developer in about 6 years now, but also got knowledge about C++, java, PHP, python and now very little about lua
#105
Posted 18 September 2013 - 05:34 AM
noxiaz, on 18 September 2013 - 04:10 AM, said:
Save it in a file. See the timer event where timerID == newFloorTimer
noxiaz, on 18 September 2013 - 04:10 AM, said:
Client code:
local keepRunning = true;
while (keepRunning) do
rednet.broadcast("who")
senderId, message, distance = rednet.receive(5)
if (message == "server") then
keepRunning = false
end
end
I’m sure it’s because of this loop but I not sure why :S
You've been programming 12 years and can't spot an infinite loop?
The loop stops when it receives a response from the server.. if there's no server then it's never going to stop.
Also if you have more than two clients, there's a queue of modem events getting bigger and bigger which probably doesn't help. (Events are put into a queue.)
noxiaz, on 18 September 2013 - 04:10 AM, said:
I guess its this line you talking about (from client): rednet.send(senderId,"add " .. explodeChar .. " " .. y .. explodeChar .. computerID .. explodeChar .. n)
At start the line looked like: rednet.send(senderId,"add " .. y .. explodeChar .. computerID .. explodeChar .. n)
but i couldn’t split the string, and thought that it was because the char was different when it was received from rednet (the explode char was # at start)
So i changed the line so the client could tell the server about what char the server need to split the string with
But now I’m keeping it this way so the explode char can be different on server and client
The problem you had was that y is a number which got appended to the \31 character code. Character codes can be 3 digits long so if y=5 then the character code becomes \315. - Your explode character is now different and you've lost the y value. If you replace \31 with \031 then that 3 digit code is never going to get messed up. If the string is \0315, only the 3 digits after the \ will get taken as the character code.
noxiaz, on 18 September 2013 - 04:10 AM, said:
Wireless modems have a range limit that varies with height and weather. - Greatest range at top of the world in clear weather, lowest at the bottom in a storm. This doesnt really make sense as if you're well underground you'll be insulated from the storm.
noxiaz, on 18 September 2013 - 04:10 AM, said:
I have been programming in C# in about 12 years now I think, and been working as a developer in about 6 years now, but also got knowledge about C++, java, PHP, python and now very little about lua
Nice and complicated? ha. I've actually tidied it up a bit for this next release.
I started teaching myself PHP and Javascript at school about 8 years ago. Last summer I graduated from uni with a degree in software engineering, but didn't really learn anything I didn't already know about programming or could have taught myself in an afternoon.
This was my first encounter with Lua but I quite like it. It's simple but meta tables make it pretty powerful.
#106
Posted 18 September 2013 - 09:08 AM
OminousPenguin, on 18 September 2013 - 05:34 AM, said:
You've been programming 12 years and can't spot an infinite loop?
The loop stops when it receives a response from the server.. if there's no server then it's never going to stop.
Also if you have more than two clients, there's a queue of modem events getting bigger and bigger which probably doesn't help. (Events are put into a queue.)
OminousPenguin, on 18 September 2013 - 05:34 AM, said:
OminousPenguin, on 18 September 2013 - 05:34 AM, said:
OminousPenguin, on 18 September 2013 - 05:34 AM, said:
This part:
handlers = {
modem_message =
function (_, sChannel, sReplyChannel, sMessage, nDistance)
..
while true do
handlers:handle(os.pullEvent())
end
It looks really nice, but when I have no idea how it works it looks pretty complicated
I’m not sure I like Lua, but its smart that it is so easy to implement into programs, so your users are able to use scripts in games like minecraft but I don’t like the syntax in Lua it’s like VS and that’s crap if you ask me
#107
Posted 18 September 2013 - 09:45 AM
noxiaz, on 18 September 2013 - 09:08 AM, said:
OminousPenguin, on 18 September 2013 - 05:34 AM, said:
The loop stops when it receives a response from the server.. if there's no server then it's never going to stop.
Also if you have more than two clients, there's a queue of modem events getting bigger and bigger which probably doesn't help. (Events are put into a queue.)
noxiaz, on 18 September 2013 - 09:08 AM, said:
OminousPenguin, on 18 September 2013 - 05:34 AM, said:
noxiaz, on 18 September 2013 - 09:08 AM, said:
OminousPenguin, on 18 September 2013 - 05:34 AM, said:
This part:
handlers = {
modem_message =
function (_, sChannel, sReplyChannel, sMessage, nDistance)
..
while true do
handlers:handle(os.pullEvent())
end
It looks really nice, but when I have no idea how it works it looks pretty complicated
handle is a function in the table 'handlers'. We know its a function so we can whack some parentheses on it and call it straight from there. The colon passes a variable 'self' to the handle function which is a reference to the handlers table.
We could instead write handlers["handle"](handlers, os.pullEvent())
Knowing this I expect you can look at the handle function and see what's going on.
noxiaz, on 18 September 2013 - 09:08 AM, said:
#108
Posted 18 September 2013 - 10:36 AM
OminousPenguin, on 18 September 2013 - 09:45 AM, said:
Is it possible to get inside the game with a method ?
OminousPenguin, on 18 September 2013 - 09:45 AM, said:
We could instead write handlers["handle"](handlers, os.pullEvent())
Knowing this I expect you can look at the handle function and see what's going on.
That was a pretty smart way to do it, think I’m going to look a little more into that, but not sure if I will use it
OminousPenguin, on 18 September 2013 - 09:45 AM, said:
Ohh sorry misspell, it was VB I was referring to
#109
Posted 18 September 2013 - 10:59 AM
noxiaz, on 18 September 2013 - 10:36 AM, said:
noxiaz, on 18 September 2013 - 10:36 AM, said:
#110
Posted 18 September 2013 - 11:27 AM
OminousPenguin, on 18 September 2013 - 10:59 AM, said:
I will let you know if i find away to do it
OminousPenguin, on 18 September 2013 - 10:59 AM, said:
The if statements are nearly wrote at the same way, your variables are typeless and you don’t need to end your lines with ; - There are ofc a lot of difference syntax with the 2 languages, but lua still reminds me of VB
#111
Posted 18 September 2013 - 12:03 PM
noxiaz, on 18 September 2013 - 11:27 AM, said:
I'll probably be posting the update tonight btw.
#113
Posted 18 September 2013 - 04:12 PM
- Added support for multiple elevators in close proximity to eachother
- Made update process much simpler (Sorry, you'll still have to install this update the old fashioned way)
- Many miscellaneous changes... paving the way for better things to come.
- Hold Ctrl+T to terminate the elevator program and return to a prompt
- Delete setup.lua and elevator-main.lua. eg > rm elevator-main.lua
- Run this: pastebin get VYwxa3su setup.lua
- Run setup.lua
- Follow the instructions
Please report any bugs.
#114
Posted 18 September 2013 - 07:58 PM
#115
Posted 19 September 2013 - 04:06 AM
It's failing to overwrite the elevator.cfg file so if you just delete that first, it should work.
I've just changed setup.lua to delete it before writing.
#116
Posted 23 September 2013 - 09:50 AM
Any other problems?
#117
Posted 23 September 2013 - 05:59 PM
-Git
#118
Posted 02 November 2013 - 09:00 PM
Any tips on what I might be doing wrong would be most appreciated.
#119
Posted 03 November 2013 - 08:48 AM
BobJames, on 02 November 2013 - 09:00 PM, said:
Any tips on what I might be doing wrong would be most appreciated.
One more thing to add, I recieved the follow error also when I was trying to get the elevator system to work:
http://i.imgur.com/NbDoyXC.png
I don't see the error everytime, but I have seen it a few times.
#120
Posted 03 November 2013 - 05:28 PM
1. The first computer you set up will say No existing elevators detected so you specify an ID for the elevator eg Home Elevator - This is the ID for the whole elevator shaft, not the floor.
2. Then you specify a name for that floor, eg Store Room
3. The second computer you set up will show The following elevator IDs were detected: Home Elevator - You want to add another floor to this elevator so you select it and press enter.
4. Then you specify a name for that floor, eg Machine Room
Now you have 1 elevator with 2 floors.
If at step 3 you make a new elevator, then they will just say No other floor discovered because it only discovers other floors with the same elevator ID.
Sorry about the 4 character limit, I've changed it to 6: http://pastebin.com/VYwxa3su
Regarding that error, the line it references is:
modem.open(os.getComputerID())os.getComputerID() is a standard function and if modem wasnt defined, you'd have got an error way earlier in the program. So I have no idea why you're getting that error. Sorry.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











