Jump to content




[Railcraft Mod] Elevator Control


  • You cannot reply to this topic
137 replies to this topic

#101 OminousPenguin

  • Members
  • 93 posts

Posted 14 September 2013 - 12:10 AM

Multiple elevators done. Just need to finish the update system to cope if some floors are out of range.

I'm afraid I'm away this weekend so you'll have to hang on a bit longer.

#102 noxiaz

  • Members
  • 7 posts

Posted 17 September 2013 - 05:15 PM

Hey OminousPenguin :D

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. :D
But there are still a lot of work to do :)

#103 OminousPenguin

  • Members
  • 93 posts

Posted 17 September 2013 - 06:53 PM

Nice job. What are your plans for the future?

I admire your lack of efficiency :P I'm sure you get much more done than I do thinking about big O of operations and storage space.

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 noxiaz

  • Members
  • 7 posts

Posted 18 September 2013 - 04:10 AM

I’m not sure what my plans are yet, but i think it will be to support the GPS function, and when a client "login" to the server it should send information back to the client if it already exist, so no need of client configuration again. This check will be done by the GPS coordinate.
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 :) - hmm and some way to remember the settings even when you logout of the server and back again, how do you handle that?

Hehe thanks :D – I have no idea how lua performs, but when everything is made by events it should be fine I hope, but the time will show.

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 that didn’t work with # so i went back to your code to see how you did it :D
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 :) your code for this project looks really nice and complicated, what is your experience with lua and other languages?

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 :D

#105 OminousPenguin

  • Members
  • 93 posts

Posted 18 September 2013 - 05:34 AM

View Postnoxiaz, on 18 September 2013 - 04:10 AM, said:

hmm and some way to remember the settings even when you logout of the server and back again, how do you handle that?

Save it in a file. See the timer event where timerID == newFloorTimer

View Postnoxiaz, on 18 September 2013 - 04:10 AM, said:

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

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.)

View Postnoxiaz, on 18 September 2013 - 04:10 AM, said:

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 that didn’t work with # so i went back to your code to see how you did it :D
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.

View Postnoxiaz, on 18 September 2013 - 04:10 AM, said:

What is the limit of floors? Is the limit based on the distance from each other when using wireless

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.

View Postnoxiaz, on 18 September 2013 - 04:10 AM, said:

That’s sounds really cool, I’m looking forward to see your code for that :) your code for this project looks really nice and complicated, what is your experience with lua and other languages?

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 :D

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 noxiaz

  • Members
  • 7 posts

Posted 18 September 2013 - 09:08 AM

View PostOminousPenguin, 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.)
As I said from start, I have no idea how lua perform J - It’s an infinite loop but with a “sleep” of 5 seconds because of the event. So this would not create any issues in any other languages I know about. And thought that each computer was running its own thread so it shouldn’t impact each other, because the code is default hosted by the client and not server (as I have understood it)

View PostOminousPenguin, on 18 September 2013 - 05:34 AM, said:

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.
Ahh okay, didn’t know about that :D – Thanks for telling me.

View PostOminousPenguin, on 18 September 2013 - 05:34 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.
Is it possible to get the range limit ? I guess this can be different from each server?

View PostOminousPenguin, on 18 September 2013 - 05:34 AM, said:

Nice and complicated? ha. I've actually tidied it up a bit for this next release.
It’s your handler I think looks so complicated, but I haven’t put much time in learning lua at all J
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 :D

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 :D

#107 OminousPenguin

  • Members
  • 93 posts

Posted 18 September 2013 - 09:45 AM

View Postnoxiaz, on 18 September 2013 - 09:08 AM, said:

View PostOminousPenguin, 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.)
As I said from start, I have no idea how lua perform J - It’s an infinite loop but with a “sleep” of 5 seconds because of the event. So this would not create any issues in any other languages I know about. And thought that each computer was running its own thread so it shouldn’t impact each other, because the code is default hosted by the client and not server (as I have understood it)
It's a timeout, not a sleep. If there has been no modem_message event for 5 seconds, rednet.receive(5) would return false.

View Postnoxiaz, on 18 September 2013 - 09:08 AM, said:

View PostOminousPenguin, on 18 September 2013 - 05:34 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.
Is it possible to get the range limit ? I guess this can be different from each server?
Yes. You can set it in ComputerCraft.cfg which is in .minecraft/config

View Postnoxiaz, on 18 September 2013 - 09:08 AM, said:

View PostOminousPenguin, on 18 September 2013 - 05:34 AM, said:

Nice and complicated? ha. I've actually tidied it up a bit for this next release.
It’s your handler I think looks so complicated, but I haven’t put much time in learning lua at all J
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 :D

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.

View Postnoxiaz, on 18 September 2013 - 09:08 AM, said:

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 :D
What do you mean by "it’s like VS"? I saw VS and thought Visual Studio but that doesn't make sense in the context.

#108 noxiaz

  • Members
  • 7 posts

Posted 18 September 2013 - 10:36 AM

View PostOminousPenguin, on 18 September 2013 - 09:45 AM, said:

Yes. You can set it in ComputerCraft.cfg which is in .minecraft/config

Is it possible to get inside the game with a method ? :) – The reason I ask is that it would be awesome to tell the user that it can only be like 62 blocks away from the server before needing a gateway

View PostOminousPenguin, on 18 September 2013 - 09:45 AM, said:

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.

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 :)

View PostOminousPenguin, on 18 September 2013 - 09:45 AM, said:

What do you mean by "it’s like VS"? I saw VS and thought Visual Studio but that doesn't make sense in the context.


Ohh sorry misspell, it was VB I was referring to :)

#109 OminousPenguin

  • Members
  • 93 posts

Posted 18 September 2013 - 10:59 AM

View Postnoxiaz, on 18 September 2013 - 10:36 AM, said:

Is it possible to get inside the game with a method ? :) – The reason I ask is that it would be awesome to tell the user that it can only be like 62 blocks away from the server before needing a gateway
I don't think so. It would be very useful so if you find that it is possible please let me know!

View Postnoxiaz, on 18 September 2013 - 10:36 AM, said:

Ohh sorry misspell, it was VB I was referring to :)
The only similarity I can see is that blocks are closed with 'end' instead of curly braces...

#110 noxiaz

  • Members
  • 7 posts

Posted 18 September 2013 - 11:27 AM

View PostOminousPenguin, on 18 September 2013 - 10:59 AM, said:

I don't think so. It would be very useful so if you find that it is possible please let me know!

I will let you know if i find away to do it :D

View PostOminousPenguin, on 18 September 2013 - 10:59 AM, said:

The only similarity I can see is that blocks are closed with 'end' instead of curly braces...

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 :D

#111 OminousPenguin

  • Members
  • 93 posts

Posted 18 September 2013 - 12:03 PM

View Postnoxiaz, on 18 September 2013 - 11:27 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 :D
The last time I used VB(6) was 7 years ago and I probably wrote a total of a hundred or so lines... so my memory is a little fuzzy :P

I'll probably be posting the update tonight btw.

#112 Git

  • Members
  • 13 posts

Posted 18 September 2013 - 03:09 PM

View PostOminousPenguin, on 18 September 2013 - 12:03 PM, said:

I'll probably be posting the update tonight btw.

Remember this guy? :D

#113 OminousPenguin

  • Members
  • 93 posts

Posted 18 September 2013 - 04:12 PM

Update 2.1.0b -> 2.2.0b
  • 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.
To update:
  • 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
Elevator ID can be anything. Examples: Elev1, I love elevators, North Shaft

Please report any bugs.

#114 Git

  • Members
  • 13 posts

Posted 18 September 2013 - 07:58 PM

One slight issue it appears... I got this right after reboot.

Posted Image

#115 OminousPenguin

  • Members
  • 93 posts

Posted 19 September 2013 - 04:06 AM

Ah that bug. I got that intermittently and then it went away.

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 OminousPenguin

  • Members
  • 93 posts

Posted 23 September 2013 - 09:50 AM

How are you finding the update?

Any other problems?

#117 Git

  • Members
  • 13 posts

Posted 23 September 2013 - 05:59 PM

I just got my first elevator working with a bit of editing. I'm using different wire colors (red, white, and blue), so I had to change the assigned colors in the main script. Everything is working GREAT! The only issue I maybe foresee is the possibility of a future update changing the wire colors back to stock..? I assume as part of the update process, you download a new main cfg? If this is the case, it may give me issues later... but I'm very happy as of now, thanks for the hard work penguin.

-Git ;)

#118 BobJames

  • New Members
  • 2 posts

Posted 02 November 2013 - 09:00 PM

Great mod OminousPenguin but I am having the hardest time trying to get my elevator system setup. I have five floor in my base, I have everything in terms of rails, dectors, computer, wireless modems and cables setup correctly including the color for the cables. I get the software installed on each of the computers, however they all say "No other floors discovered, Once the elevator program is started on other floors, they will appear here." What is odd is as I am setting up the second thru fifth floors I can see the list of the other floor the programs detects so I don't know why it can't detect them once the programs is done and I am trying to use the elevator. I don't know how to use the GPS tool since my 'Z' coordinate is -3805 for example and the programs only seems let me type in 4 charactors in that field.

Any tips on what I might be doing wrong would be most appreciated.

#119 BobJames

  • New Members
  • 2 posts

Posted 03 November 2013 - 08:48 AM

View PostBobJames, on 02 November 2013 - 09:00 PM, said:

Great mod OminousPenguin but I am having the hardest time trying to get my elevator system setup. I have five floor in my base, I have everything in terms of rails, dectors, computer, wireless modems and cables setup correctly including the color for the cables. I get the software installed on each of the computers, however they all say "No other floors discovered, Once the elevator program is started on other floors, they will appear here." What is odd is as I am setting up the second thru fifth floors I can see the list of the other floor the programs detects so I don't know why it can't detect them once the programs is done and I am trying to use the elevator. I don't know how to use the GPS tool since my 'Z' coordinate is -3805 for example and the programs only seems let me type in 4 charactors in that field.

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 OminousPenguin

  • Members
  • 93 posts

Posted 03 November 2013 - 05:28 PM

Sounds like you are confusing elevators with floors. You can specify different elevator IDs so that you can have multiple elevators near eachother without them interfering.

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