Jump to content




How to use Bedrock (Bedrock Documentation)


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

#41 SpencerBeige

  • Members
  • 263 posts

Posted 19 February 2015 - 12:08 AM

View Postoeed, on 16 February 2015 - 06:59 AM, said:

View Postspyman68, on 16 December 2014 - 02:11 AM, said:

Could you try to explain the menus a little better? I was confused where I had to paste the code and such.
I don't really have time to go in to much detail, but you call the function to show menus when you click a button.

View Post__Kiwi, on 30 December 2014 - 05:38 PM, said:

I love this framework, but I have a question:
How can I create a "TextArea" ( multiline TextBox)? If I change the height of the TextBox object, then I can't use the enter key for jump a line.

(Sorry for my bad english)
Hmmm, yea I'll probably try to add that at some point, if I make Ink 2 I'll definitely have to.

View Postslow-coder, on 16 February 2015 - 03:41 AM, said:

could you plz shorten the syntax required to get bedrock?
These forums aren't powered by circa-1990's texting, so please just write a real sentence for goodness sake, honestly it just makes people think a lot less of you and will be less inclined to do what you ask, as in this situation.

So, no. It's a single line and every bit of it is required.
ok, i get it, you don't have you be rude. i was just thinking a bit of it wasn't required because throughout the line, you were testing for oneos api or something, so i was seeing if that was RLY required

#42 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 19 February 2015 - 12:24 AM

View Postslow-coder, on 19 February 2015 - 12:08 AM, said:

ok, i get it, you don't have you be rude. i was just thinking a bit of it wasn't required because throughout the line, you were testing for oneos api or something, so i was seeing if that was RLY required

No, you still haven't got it. I know I am a little obsessive about these sort of things, but really, just learn to construct a sentence with words and capital letters. Until then I and most others aren't going to pay attention to you.

#43 Elsys656

  • Members
  • 17 posts

Posted 06 March 2015 - 12:16 AM

Oeed I have a question about how to construct a view that lays out like this
{
Window
{
children={
scrollview
children={
buttons/labels/etc
scrollview aligned to 50% of x and y so the bottom left of the screen
children={
buttons/labels/etc
}
scrollview bottom right of the screen
children={
buttons/labels/etc
}
}
}
I have a view file set up like this the 2 bottom scrollviews objects are dynamically created.
Is it possible to have a scrollview inside a window that has an overall status pane or section on top of a child scrollview
with those dynamically created objects. Another way of looking at it would be how to go about modifying bedrock to accept nested views as one view.
The below will not load and errors out due to the Children=portion of the array.
Spoiler


#44 plato2000

  • New Members
  • 2 posts

Posted 06 March 2015 - 11:54 PM

Hi, I'm trying to make a control system using Bedrock. I think I found a bug, but I have no idea where it could be.
The problem occurs here:
program:GetObject("Refresh").OnClick = function(self, event, side, x, y)
   x = tostring(cell.getEnergyStored()) .. " RF"
   program:GetObject("PowerStored").Text = x
  end
I've tried it with printing the value of x right there and that works, but when I try to set the value, it doesn't work. I can set the value to anything as long as I am not getting
cell.getEnergyStored()
in the same block.

#45 Elsys656

  • Members
  • 17 posts

Posted 07 March 2015 - 07:51 PM

Just wanted to say I resolved my issues on the other hand Plato i'd create a function with no args and do all your value updates there then use a repeating timer in either your OnViewLoad method or in run depending on how many views you have. If you don't need to update that many things and want there to be a refresh button define x as local in the onclick. Program is likely getting variables confused.

#46 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 07 March 2015 - 11:34 PM

View Postplato2000, on 06 March 2015 - 11:54 PM, said:

Hi, I'm trying to make a control system using Bedrock. I think I found a bug, but I have no idea where it could be.
The problem occurs here:
program:GetObject("Refresh").OnClick = function(self, event, side, x, y)
   x = tostring(cell.getEnergyStored()) .. " RF"
   program:GetObject("PowerStored").Text = x
  end
I've tried it with printing the value of x right there and that works, but when I try to set the value, it doesn't work. I can set the value to anything as long as I am not getting
cell.getEnergyStored()
in the same block.
I doubt it's causing the issue, but don't use a variable name that's already declared (x).

So there's no error message, it just doesn't work?

Maybe use something to log or show what cell.getEnergyStored() is, even just doing this will probably help.
error(cell.getEnergyStored())

But nothing jumps out as being really wrong.

Elsys656 is right though, a timer might be a better option.

Edited by oeed, 07 March 2015 - 11:36 PM.


#47 Elsys656

  • Members
  • 17 posts

Posted 08 March 2015 - 05:44 PM

Sorry to bother you again Oeed I have my view displaying like I want however my Scrollview does not scroll it does display a scrollbar it's generated content using AddObject and in the OnUpdate event I have it set to call self:UpdateScroll()

Here's the relevant section when adding buttons I add a variable to the button Object named Index to keep track of which button is being clicked.
Spoiler
I used to just call UpdateScroll after adding buttons this also "works" except the scrollview still doesn't scroll tried this in OnUpdate so it would call whenever changes were made to the content.
Spoiler
This sets a private variable (local inside program scope) inside the onClick handler. The buttons load and close the view just fine
Spoiler
This portion is where I use reactorIndex the turbine handler/buttons all behave identically but set a different variable I didn't want to account for by other means setting name to the same thing across them all and checking a second variable to see what subtype the button was.
Spoiler

I would also like to load the objects from a file if possible dynamically creating the file on program run so it doesn't need to recreate objects all the time and I can just update their states. In my main.view update routine pretty much exactly like LoadView but without removing everything first. At the moment however more concerned with my first question.

By the way I tried switching to list views and it doesn't seem to propagate any click events even attached exactly as in the SaveFile dialog and still doesn't scroll

Edited by Elsys656, 08 March 2015 - 10:59 PM.


#48 roombascj

  • Members
  • 8 posts

Posted 08 March 2015 - 09:05 PM

I am confused on how to use scroll views and scroll bars...

#49 Elsys656

  • Members
  • 17 posts

Posted 10 March 2015 - 01:53 AM

I don't think you can use a Scrollview by itself I looked into the sources of other bedrock apps making use of scrollviews and they all define custom objects derived from scrollview that include a custom object based on a view. I have tried doing this and gotten fairly close just gotta define Height in all objects not sure which object it's referring to cause I have default height values set in my code and whatever objects of that type I create should just initialize with the default height value. (It doesn't do this so I must not be setting something on object creation haven't yet figured out what that is.)

More importantly I can't seem to find out how the structure of the Items Table should look except that I can guess something to this effect

YourcustomObject = {
Each base object defined in your onload function would require
{
Name=(whatever you named this subobject)
Whatever else you want to set the objects properties to
},
{
another object
}
more of these to match the number of elements in your custom object (more like an object structure)
}

Then set that table to Items of your custom Scrollview it should render but I'm doing something incorrect I'm guessing in my table I didn't define what type of object in my insert probably more like
{
Type=mycustomobject
Children={
define custom object
}
}
ill see if that format is more acceptable

Edited by Elsys656, 10 March 2015 - 02:04 AM.


#50 Elsys656

  • Members
  • 17 posts

Posted 12 March 2015 - 06:54 AM

Ok so I realized what had been done incorrectly and it's drawing now, not sure about the scrollbars exactly but it should. My problem is that my api that interfaces with peripherals is not returning control to bedrock... I need to somehow yield to bedrock to allow it to process events how should I do this? Apparently os.sleep was messing with the drawing functions. Scrolling is working now Yay. Yes button clicks are propagating properly as well.

Edited by Elsys656, 12 March 2015 - 09:46 AM.


#51 roombascj

  • Members
  • 8 posts

Posted 14 March 2015 - 06:11 PM

Is there a function or way to make a object move around the screen or animate?

#52 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 15 March 2015 - 12:40 AM

View PostElsys656, on 12 March 2015 - 06:54 AM, said:

Ok so I realized what had been done incorrectly and it's drawing now, not sure about the scrollbars exactly but it should. My problem is that my api that interfaces with peripherals is not returning control to bedrock... I need to somehow yield to bedrock to allow it to process events how should I do this? Apparently os.sleep was messing with the drawing functions. Scrolling is working now Yay. Yes button clicks are propagating properly as well.
Yeah, you can't use sleep calls or things that yield anywhere.

View Postroombascj, on 14 March 2015 - 06:11 PM, said:

Is there a function or way to make a object move around the screen or animate?
Yes, use the function 'AnimateValue'.

--	   value name   from  to  duration  callback
-- from, duration and callback can be nil
-- from defaults to the current value
-- duration defaults to 0.2
myButton:AnimateValue('Width', 10, 20, 0.5, function()end)

Edited by oeed, 15 March 2015 - 12:46 AM.


#53 roombascj

  • Members
  • 8 posts

Posted 15 March 2015 - 12:44 AM

But i still don't understand how to use a scrollbar or a scroll view in a program.

#54 Elsys656

  • Members
  • 17 posts

Posted 15 March 2015 - 03:57 AM

you need to create a custom object based on view lay the objects out like you want them to appear it needs to have a static height any events you should handle with those objects inside the ScrollView need to be defined inside that object or another file named the exact same in the APIs folder I found it easier to do it right in the custom object.

Inherit = 'View'

Width = 50
Height = 1
AssocButton = nil

OnLoad = function(self)
--[[this defines the program context so that the object can access your instance of bedrock... sometimes its better to make a new instance but that depends on the program.]]
local program = self.Bedrock

--[[I set my click events up here you would do the same for any other events you need to attach to objects inside your scrollview]]
--reactor click event
function reactorClick(self, event,side,x,y)
program.Timers = {}
program.reactorIndex = self.Index
program:LoadView('reactor')
end
--turbine click event
function turbineClick(self, event,side,x,y)
program.Timers = {}
program.turbineIndex = self.Index
program:LoadView('turbine')
end

--[[Here I set up the objects in my case some labels and buttons associated with those labels thus AssocButton :D/>]]
self:AddObject({
X=2,
Y=1,
Type='Label',
Width=12,
Height=1,
Name='reactorLabel',
Text='Reactor ',
Visible=false
})

self:AddObject({
X=14,
Y=1,
Width=6,
Height=1,
Type='Button',
Text='Status',
Name='reactorButton',
Visible=false,
BackgroundColour = "red",
OnClick = reactorClick
})

self:AddObject({
X=28,
Y=1,
Height=1,
Type='Label',
Width=12,
Height=1,
Name='turbineLabel',
Text='Turbine ',
Visible=false
})

self:AddObject({
X=40,
Y=1,
Height=1,
Width=6,
Type='Button',
Text='Status',
Name='turbineButton',
Visible=false,
BackgroundColour = "red",
OnClick = turbineClick
})

--[[Call OnUpdate to pull the variables that we didn't set here or any changed ones]]
self:OnUpdate('AssocButton')
end

--[[OnUpdate set variables to Objects like you would normally]]--
OnUpdate = function(self, value)
--[[value holds the type of object in this case AssocButton our custom type]]
if value == 'AssocButton' then
--check for nil values
--[[self is basically your current bedrock instance set these as normal and check for nil just because if your program passes an empty argument you'll be able to track it down easier]]
if self.AssocButton.objIndex ~= nil then
self:GetObject('reactorButton').Index = self.AssocButton.objIndex
self:GetObject('reactorLabel').Text = 'Reactor '..self.AssocButton.objIndex
self:GetObject('turbineButton').Index = self.AssocButton.objIndex
self:GetObject('turbineLabel').Text = 'Turbine '..self.AssocButton.objIndex
end
--check if reactor has nil values
if self.AssocButton.reactorVisible ~= nil then
self:GetObject('reactorLabel').Visible = self.AssocButton.reactorVisible
self:GetObject('reactorButton').Visible = self.AssocButton.reactorVisible
if self.AssocButton.reactorOnline == true then
self:GetObject('reactorButton').BackgroundColour = "green"
else
self:GetObject('reactorButton').BackgroundColour = "red"
end
end
-- check if turbine has nil values
if self.AssocButton.turbineVisible ~= nil then
self:GetObject('turbineLabel').Visible = self.AssocButton.turbineVisible
self:GetObject('turbineButton').Visible = self.AssocButton.turbineVisible
if self.AssocButton.turbineOnline == true then
self:GetObject('turbineButton').BackgroundColour = "green"
else
self:GetObject('turbineButton').BackgroundColour = "red"
end
end
end
end

Then set up a collection view object and also save it to the Objects folder next to your program (just like Views)


--[[The default values for a AssocButtonCollectionView yours would be named something else but its just like other objects in Bedrock you can set default values otherwise it would inherit whatever you don't set from ScrollView]]
Inherit = 'ScrollView'
UpdateDrawBlacklist = {['NeedsItemUpdate']=true}
Items = false
NeedsItemUpdate = false
TextColour = colours.black
BackgroundColour = colours.white

--[[this draws the object itself using bedrock drawing methods you could really draw anything you like here mines just a real basic blank pane]]
OnDraw = function(self, x, y)
  if self.NeedsItemUpdate then
   self:UpdateItems()
   self.NeedsItemUpdate = false
  end
  Drawing.DrawBlankArea(x, y, self.Width, self.Height, self.BackgroundColour)
end

--[[What to do on item update a scrollview takes an argument called Items that is a table of values you saw defined in the AssocButton object on update you can also add base objects here if you don't need a number of them]]
UpdateItems = function(self, value)
  self:RemoveAllObjects()
  local x = 1
  local y = 1
--[[a loop that iterates over all the tables inside a 2d table I set up to pass values to each sub-object in AssocButton]]
  for i, assocButton in ipairs(self.Items) do
   self:AddObject({
   X=x,
   Y=y,
   Height = x,
   Type = 'AssocButton',
   AssocButton = assocButton --[[Here you can see the type we defined earlier in AssocButton is used]]
   })
--[[My scrollview is very basic but you can change the positioning of items to have multiple "AssocButton" objects on one line or skip a line or lines using x and y values]]
  y = y + AssocButton.Height
  end
self:UpdateScroll()
end

--[[this forces the scrollview to initialize and pass its item array to my subObjects]]
OnUpdate = function(self, value)
if value == 'Items' then
  self.NeedsItemUpdate = true
end
end

--[[Do this for each value in your sub object wrap that in a table and pass it to your CollectionView]]
AssocButton.whatevervalue
AssocButton.whatevervalue

I know my explanation is probably close to clear as mud but it's all stuff I had to figure out from looking at OneOS code and Bedrocks source
Then in your view file under Type="yourcollectionview" position it as normal etc.

#55 roombascj

  • Members
  • 8 posts

Posted 15 March 2015 - 02:14 PM

Im still very confused on how to use them though.

Edited by roombascj, 15 March 2015 - 07:35 PM.


#56 Elsys656

  • Members
  • 17 posts

Posted 15 March 2015 - 06:07 PM

I'm not re-quoting all that just because it will turn into a giant wall of text my fault for not spoiler tagging everything. Anyway the call to self:UpdateScroll() actually draws the object so you don't need to worry about that any objects you set values for should appear and scroll its basically a way to make tons of objects appear in a small space. That particular ScrollView is being used to list 4 reactor status pages and 56 turbine status pages on one screen. I'm releasing the program within the next half hour as I have 99% if not all the kinks worked out. My computer system itself is the only thing keeping the program from locking up occasionally... 56 turbines is quite a lag machine but the 1.3-1.4 mil rf per tick produced is pretty sick. Originally did all this cause on 1.6.4 AtomicScience is very broken, I was in the process of fixing it up but because of how it had been ported to mostly proprietary code it got to be more of a headache than it was worth.

Further completely unrelated note: At least I found some use for the Electromagnetic Glass I went to the trouble of making(its now keeping me from frying myself on my 32 MFR Drills)

Edited by Elsys656, 15 March 2015 - 06:10 PM.


#57 roombascj

  • Members
  • 8 posts

Posted 19 March 2015 - 02:30 AM

Is there any way to put a text box inside of an alert window?

Edited by roombascj, 19 March 2015 - 09:46 PM.


#58 cdel

  • Banned
  • 496 posts
  • LocationMelbourne, Australia

Posted 22 March 2015 - 05:00 AM

I don't want my Views folder in "/" , how can I move it to "/directory" ?

#59 roombascj

  • Members
  • 8 posts

Posted 22 March 2015 - 07:58 PM

With the custom windows, can i run a program in them and how?

#60 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 22 March 2015 - 08:25 PM

View Postcdel, on 22 March 2015 - 05:00 AM, said:

I don't want my Views folder in "/" , how can I move it to "/directory" ?

I believe there's a program.ViewPath variable for that.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users