This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
RlonRyan's profile picture

How to leverage Bedrock API?

Started by RlonRyan, 15 August 2014 - 02:58 AM
RlonRyan #1
Posted 15 August 2014 - 04:58 AM
I am having several issues attempting to leverage oeed's bedrock api to create guis for my programs. However I am running into a consistent errors of either "could not load view" or "view does not exist." If someone could tell me what I am doing wrong within this infuriating program… it would be very appreciated!
Code

Main Program


-- Obtain view(s)
if (not fs.exists("Views/main.view")) then
	shell.run("pastebin get F8WKXGGe Views/main.view")
end

local program = Bedrock:Initialise()

program:LoadView("Views/main.view")

program:Run(function()
program:GetObject("HelloLabel").Text = "Hello! I'm a Label!"
program:GetObject("HelloLabel").BackgroundColour = colours.lightBlue
end)


Main View


{
  Children={
		{
		  X=2,
		  Y=2,
		  Name="HelloLabel",
		  Type="Label",
		  Text="Hello! I\'m a Label!"
		},
		{
		  X=2,
		  Y=4,
		  Name="HelloButton",
		  Type="Button",
		  Text="Hello! I\'m a Button!"
		}
  },
  BackgroundColour="white"
}


Thanks!
RlonRyan
Edited on 15 August 2014 - 04:52 AM
Dragon53535 #2
Posted 15 August 2014 - 05:26 AM
Looking at Oeed's documentation on the views, i noticed that you attempted to copy his test code. The problem i'm seeing is the apostrophe's he's used on the BackgroundColour. That's my guess as if it was supposed to be quotes he would of used them there, so i would copy these: and test to see if that's your problem.
RlonRyan #3
Posted 15 August 2014 - 06:35 AM
Looking at Oeed's documentation on the views, i noticed that you attempted to copy his test code. The problem i'm seeing is the apostrophe's he's used on the BackgroundColour. That's my guess as if it was supposed to be quotes he would of used them there, so i would copy these: and test to see if that's your problem.

The apostrophes are generally the same as quotes. I believe that lua treats them as functionally the same.

As for Oeed's documentation and test code… I can not make heads or tails of it…

[Edit] Just checked. According to <a href="http://www.lua.org/pil/2.4.html">Lua's Documentation</a> the quotes and apostrophes are functionally the same, and it is recommended to use the same style throughout a program.
Edited on 15 August 2014 - 04:40 AM
RlonRyan #4
Posted 15 August 2014 - 06:43 AM
Oh… and while I am on the subject… what about a good emulator to test this code on instead of in-game?
Win7yes #5
Posted 15 August 2014 - 06:56 AM

program:LoadView("Views/main.view")
Is an incorrect formatting for the function. Bedrock automatically detects the Views folder inside whatever folder the main program is. So the correct way to use the function would be:

program:LoadView("main")
I also noticed, you are not setting some vital parts Bedrock seems to need. There's a line of code that Oeed says you have to copy. Copy and paste it at the top of the program. That line doesn't only download Bedrock but also set some stuff Bedrock needs.
RlonRyan #6
Posted 15 August 2014 - 07:00 AM
Found it!

Just need to add this line to the top of the program:
Bedrock.ProgramPath = ""

[Edit]Not
Bedrock.ProgramPath = shell.getRunningProgram()
as there is no way to save to the directory of the program…
Edited on 15 August 2014 - 05:02 AM