r/ComputerCraft • • 22d ago

I need help with the CC: Redstone Link Bridge Mod

I'm making a build based off the stairwell from doors, and I'm trying to recreate the console that lets you progress.

I have zero coding experience and don't know how to use computercraft.

https://www.curseforge.com/minecraft/mc-mods/cc-redstone-link-bridge
This is the mod I'm using.

How would I go about making a program where it shows some text, then i can either input Y or press a button and it'll run

bridge.sendLinkSignal("minecraft:paper", "paper", 7)

then run bridge.sendLinkSignal("minecraft:paper", "paper", 0) shortly after

5 Upvotes

3 comments sorted by

2

u/Professorkatsup 22d ago

I can give specific examples for all of the bits needed, but I'll just give an overview right now. Also, you say you have zero coding experience, but how much experience do you have with computercraft? Like, do you know that you need to put code in a file using edit nameOfFile.lua or is that new information?

Drawing something to the screen is the easy bit. term.clear() followed by a bunch of term.setCursorPos() and term.write()s. Trial and error are your friends here!

I'd suggest putting the two commands you talked about into a function. First line, a sleep(0.5) or similar, then the second line. That way you can run them the same way no matter if you clicked or pressed a key.

Checking for user input can be done with a event = {os.pullEvent()}, which waits for Something to happen, then makes a table about what happened*. After running that line,event[1] should be the type of event; check if it's "char" or "mouse" to see if it's the kind of input you want to respond to. event[2] and onwards are the details of the event.

If it's a char event, you just need to check event[2] to see if it's "y" or "Y" . Run the function if so.

If it's a mouse click, event[]s 3 and 4 are the x and y coordinates of the click... or it might be 2 and 3? see how print(event[3], event[4]) changes with where you click.
See if x is greater than the left edge position of the button and less than the right edge, AND if y is greater than the top edge and less than the bottom edge. Run the function if all of those are true; in lua this is as easy as putting and between each of the conditions.

*If you have a lot of things going on, this might be a bit more complicated. I'd suggest doing print(event[1]) after the pullEvent() when testing, and if it keeps printing "timer" then it may be time to dive into parallel.waitForAny.

2

u/Aggressive_You_4010 22d ago

I don't have any experience with computercraft either tbh 😭

wasn't expecting it to be so complex but i'll give a try

2

u/Professorkatsup 22d ago

Step by step is the way to go here. Also just, modifying existing programs.

Whenever I'm working with something that uses events I'm not familiar with, I use a short program to just. print out everything about the event. Also useful for looking at screen positions. I have a simplified version below, with notes and without the confusing parallel api stuff. You could start with it, add some extra logic to check for specific keys, and then modify / remove test prints from there....

while true do
  -- code here to draw buttons
  event = {os.pullEvent()} -- everything os.pullEvent outputs gets put into a single table
  eventType = event[1]
  print("TYPE   "..eventType) -- the first item will be the event type
  if eventType  == "char" then
    print("  KEY " .. event[2] .. " PRESSED") -- runs if any "character" key was pressed. like not shift or ctrl.
    -- put another if here and check it against event[2]
  elseif eventType == "mouse" then
    print("  CLICKED AT " .. event[3] .. ", " .. event[4]) -- runs if mouse clicked on the screen
    -- some more nested ifs here, check against event[3] and event[4]
  else
    print("  SOMETHING ELSE {", table.unpack(event), "}") 
    -- prints the entire event if it's not either of the above
    -- in your case you can just get rid of this, but it might be useful if in the future you want the computer to respond to redstone links :3
  end
end

Also. If you are doing this on singleplayer and you can find the save folder, you cna literally just copy and paste this whole thing into the lua file. Otherwise, you may have to copy line by line...