Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Staircase

Detecting and Interpretating redstone levels

Question

Im new to this mod and to lua. Im trying to start with a simple program that can read redstone signals and detect their levels.

I have basic lua knowledge, knowing commands like [do], [if], [if else], [read] and [while]. A bit of boolean [True, false] and create variables.

I made a small computer with the redstone card (and the essentials like EEPROM, GPU, CPU and RAM). Its connected with red wires from red power that are connceted to a lever. I have the compat module from redpower installed.

My main question is what I need to write in the .lua file to be able to use the redstone card and what commands I need to the program detect the signal and use it for a boolean variable or something else?

 

Thank you

Mr. Stairs

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Once you've got a computer properly setup with OpenOS on it (which you can get by crafting a Floppy Disk with OpenOS on it, crafting recipes may vary please check on your own), the first thing you'll get into is a terminal.

This is just a basic tutorial on how to do what you're looking for (and there's no need for any compat modules from redpower to read vanilla minecraft redstone signals).

Once you boot up your computer you should end up in the openos terminal window. First thing to do is open up a new script.
To do so in OpenOS, type "edit" without quotes and then the name of your file, let's say redstone1 (it should look like this: edit redstone1)
Once you press enter you'll get into editing mode.

It's just like notepad you just type in the program and it will do whatever you desire.
Now, in OpenOS, you can import external libraries that can help you with various things. In your case, we'll need to import few of them:
 

local component = require("component")
local sides = require("sides")


This will set a new local variable (don't mind the local as of now), which will contain the component library and the sides library.
Now, we can use the component library to access methods related to the redstone card you have in your computer.
To do so, we must get a so-called component proxy to the redstone card. There's how it's done:

local redstone = component.redstone


What we must do now is determine which side do we want to detect the signal from.
To do so, using the sides library we can pick a side:
 

local side = sides.back


This for example selects the 'back' side of the computer.
Now, to get information about what redstone signal is in the back of the computer, we can do so:
 

local signal = redstone.getInput(side)


Finally, to draw the result on the screen, we can do so:
 

print(signal)

 

Finally, by pressing the combination of keys CTRL + S you can save your file, and CTRL + W to exit the editor.
You can further use the signal variable in your program to whatever your needs are.
Here's the fully assembled script:
 

local component = require("component")
local sides = require("sides")

local redstone = component.redstone

local side = sides.back

local signal = redstone.getInput(side)

print(signal)

Hope I helped :)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.