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

Server Rule Board. Dual Screens Single GPU

Question

Guest lordwolf76

Hello All. I am trying to wrap my head around Lua, and having some problems.
Kodos and Sangar have both assisted me in IRC, but when I try to implement it ingame, I get errors.

 

I am Building Rules, Staff, Events, etc... Boards at our Spawn.

The Goal is to have a Static Screen on Top, Showing the word Rules,

While the Larger Screen below it scrolls our server Rules.

I can get either part to work alone, but adding the second monitor breaks everything.

 

I know I am just missing something in my Syntax, but I have tried to follow the examples, and am coming up short.

 

This file is set as my Autorun.lua for our Rules Monitor

I know the addresses for the 2 screens are correct.

for line 5 I have tried

local component.gpu.bind("d538b568") 

but it throws errors also. The current code gives me a 

 

/autorun.lua:5: unexpected symbol near '.'

 

the require("event") is just in there, so I can Break out of the while true loop, to edit Rules, etc..
I know that doing so throws an error, but No Player will ever be able to Click the Monitor, or have access to the Computer.

 

 

 

I am Loving this mod, and it's realism over the "other" mod, 

but am finding the documentation to be very hard to learn from.

 

I look forward to properly learning to code with this mod,

and had figured that this "simple" script would be a good place to start.

local comp = require("component")
local event = require("event")
local gpu = comp.gpu
while true do
local comp.gpu.bind("d538b568")
gpu.setResolution(5, 1)
gpu.setBackground(0XFFFF00)
gpu.setForeground(0XFF0000)
print("RULES")
local comp.gpu.bind("c5d82d9c")
gpu.setResolution(30, 6)
gpu.setBackground(0XFF0000)
gpu.setForeground(0X00CC00)
print("")
print("No PVP in Survival Map")
print("We have an Anarchy World")
print("and Arenas for PVP")
print("")
os.sleep(3)
print("No Grief in Survival")
print("Raiding IS allowed in")
print("Areas NOT Claimed by a Town")
print("")
os.sleep(3)
print("Grief and PVP are")
print("Encouraged in the")
print("Anarchy Map")
print("")
os.sleep(3)
print("")
print("")
print("No Asking for Staff Positions")
print("")
os.sleep(3)
print("No Excessive Swearing")
print("ie: The Desire to Fornicate")
print("with Feces. Needs to only be")
print("Stated ONCE ")
os.sleep(3)

end
Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0
Guest lordwolf76

Not sure I properly phrased my question.

 

Using the first 5 lines of code, what is the proper syntax to Bind a GPU to one of two screens?

local comp = require("component")
local event = require("event")
local gpu = comp.gpu
while true do
local comp.gpu.bind("d538b568")
Link to post
Share on other sites
  • 0

Try checking that the GPU/screen binding actually succeeds. Print some text before rebinding, then print the return value of gpu.bind (once, no need to put it in an infinite loop) and print some text again:

local component = require("component")

local gpu = component.gpu

local SCREEN_ONE = "d53"

local SCREEN_TWO = "c5d"

print("Rebinding... " .. tostring(gpu.bind(SCREEN_ONE)))

print("This should appear on the first screen.")

print("Rebinding... " .. tostring(gpu.bind(SCREEN_TWO)))

print("This should appear on the second screen.")

If that succeeds, continue from there. Also note that there's no need to ever redraw the first screen if its contents shouldn't change. Unless you explicitly clear the screen its contents should stay until you break the screen block.

Link to post
Share on other sites
  • 0
Guest lordwolf76

I see what I was doing wrong, so.. Thank you.

 

gpu was already set to gpu.bind with the local variable line.

 

 

But....

I pasted your code in a new file, and ran it,

 

I get

Rebinding... nil
This should appear on the first screen.
Rebinding... nil
This should appear on the second screen.

it runs, but on One screen.

 

I modified my code to have the correct gpu.bind, and to have the while true before the second bind, and after the first monitor should have completed it's print.

 

and now it runs without errors, but it is 100% random as to which monitor it will run the entire program on.

It picks one, seemingly at random, and runs the entire program. It does not rebind at all.

This is so confusing, and driving me a little crazy.

Link to post
Share on other sites
  • 0

It might be that when unbinding, the previous screen is clearded...

I'm quite certain that isn't the case. At some point I had two screens attached to one computer, and when changing the primary screen from one to the other, the old one kept its text even after the computer was shut down. O_O

Link to post
Share on other sites
  • 0

... The current code gives me a 

 

/autorun.lua:5: unexpected symbol near '.'

 

EDIT:  Wait!  It's the "local".  Remove "local" from in front of comp.gpu.bind.  (I'll leave my original post, in case it ends up being an issue after all, but I'm 95% sure it's the "local" :) )

 

I'm just heading to bed, so my apologies for the drive-by attempt at helping... but I used to get this error when I wrote programs in Notepad++, before I switched the encoding to "Encode in UTF-8 without BOM". Other encodings (... codings? encodes?), like ASCII, use hidden characters for things like line breaks that OC doesn't like.

You can quickly check this by opening the program in OC's edit terminal---if you see a question mark in a box on line 5, delete it and see if that solves your problem. (Otherwise, I can't see anything that would be flagged as an "unexpected symbol".)

If that does prove to be the problem, you can prevent it from happening in the future by switching the encoding to UTF-8 without BOM. (It's under the Encoding menu in Notepad++, and should be easy-enough to find if you're using a different editor.)

 

Link to post
Share on other sites
  • 0
Guest lordwolf76

EDIT:  Wait!  It's the "local".  Remove "local" from in front of comp.gpu.bind.  (I'll leave my original post, in case it ends up being an issue after all, but I'm 95% sure it's the "local" :) )

 

 

 

The main issue was indeed the Local. It dawned on me that 

local gpu = comp.gpu

meant I just needed to use gpu.bind, and not local comp.gpu.bind.

 

however ..

 

 

Try checking that the GPU/screen binding actually succeeds. Print some text before rebinding, then print the return value of gpu.bind (once, no need to put it in an infinite loop) and print some text again:

local component = require("component")
local gpu = component.gpu

local SCREEN_ONE = "d53"
local SCREEN_TWO = "c5d"

print("Rebinding... " .. tostring(gpu.bind(SCREEN_ONE)))
print("This should appear on the first screen.")
print("Rebinding... " .. tostring(gpu.bind(SCREEN_TWO)))
print("This should appear on the second screen.")
If that succeeds, continue from there. Also note that there's no need to ever redraw the first screen if its contents shouldn't change. Unless you explicitly clear the screen its contents should stay until you break the screen block.

 

 

When I try this, pasted exactly into a new file, and run.

 

It Prints 

Rebinding... nil
This should appear on the first screen.
Rebinding... nil
This should appear on the second screen.

On ONE Screen, and is completey random as to which of the two screens it prints on.

Link to post
Share on other sites
  • 0
  • Solution

When I try this, pasted exactly into a new file, and run.

 

It Prints 

Rebinding... nil
This should appear on the first screen.
Rebinding... nil
This should appear on the second screen.

On ONE Screen, and is completey random as to which of the two screens it prints on.

It turns out that gpu.bind requires a full address and doesn't automatically expand partial addresses. Instead you need to use component.get to expand the address:

local SCREEN_ONE = component.get("d53")
local SCREEN_TWO = component.get("c5d")

This will store the full addresses of the two screens in SCREEN_ONE and SCREEN_TWO, which you can now use directly with gpu.bind.

Link to post
Share on other sites
  • 0
Guest lordwolf76

Thank You to everyone who helped me solve this issue.

 

dgelessus     I marked Your Answer as best, because it Truly Solved the problem.

 

 

It turns out that gpu.bind requires a full address and doesn't automatically expand partial addresses. Instead you need to use component.get to expand the address:

local SCREEN_ONE = component.get("d53")
local SCREEN_TWO = component.get("c5d")

This will store the full addresses of the two screens in SCREEN_ONE and SCREEN_TWO, which you can now use directly with gpu.bind.

I never would have gotten that figured out by reading the wiki alone.

My Rules board works Perfectly now.

I will edit this later, and Paste my code in a code box as a spoiler, in case it will help anyone else later.

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.