Updated Basalt (markdown)
129
Basalt.md
129
Basalt.md
@@ -13,16 +13,16 @@ create a frame without a parent
|
|||||||
````lua
|
````lua
|
||||||
local mainFrame = basalt.createFrame("myFirstFrame"):show()
|
local mainFrame = basalt.createFrame("myFirstFrame"):show()
|
||||||
````
|
````
|
||||||
**args:** the id as string<br>
|
**parameters:** string name<br>
|
||||||
**returns:** frame object<br>
|
**returns:** new frame object<br>
|
||||||
|
|
||||||
## basalt.removeFrame
|
## basalt.removeFrame
|
||||||
removes the frame
|
removes a frame (only possible for non-parent frames)
|
||||||
````lua
|
````lua
|
||||||
local mainFrame = basalt.createFrame("myFirstFrame"):show()
|
local mainFrame = basalt.createFrame("myFirstFrame"):show()
|
||||||
basalt.removeFrame("myFirstFrame")
|
basalt.removeFrame("myFirstFrame")
|
||||||
````
|
````
|
||||||
**args:** the id as string<br>
|
**parameters:** string name<br>
|
||||||
**returns:**-<br>
|
**returns:**-<br>
|
||||||
|
|
||||||
## basalt.getFrame
|
## basalt.getFrame
|
||||||
@@ -31,7 +31,7 @@ With that function you can get frames, but only frames without a parent!
|
|||||||
basalt.createFrame("myFirstFrame")
|
basalt.createFrame("myFirstFrame")
|
||||||
basalt.getFrame("myFirstFrame"):show()
|
basalt.getFrame("myFirstFrame"):show()
|
||||||
````
|
````
|
||||||
**args:** id of the frame<br>
|
**parameters:** string name<br>
|
||||||
**returns:** frame object<br>
|
**returns:** frame object<br>
|
||||||
|
|
||||||
## basalt.getActiveFrame
|
## basalt.getActiveFrame
|
||||||
@@ -40,16 +40,25 @@ returns the currently active (without a parent) frame
|
|||||||
basalt.createFrame("myFirstFrame"):show()
|
basalt.createFrame("myFirstFrame"):show()
|
||||||
basalt.debug(basalt.getActiveFrame():getName()) -- returns myFirstFrame
|
basalt.debug(basalt.getActiveFrame():getName()) -- returns myFirstFrame
|
||||||
````
|
````
|
||||||
**args:** -<br>
|
**parameters:** -<br>
|
||||||
**returns:** frame object<br>
|
**returns:** frame object<br>
|
||||||
|
|
||||||
## basalt.startUpdate
|
## basalt.autoUpdate
|
||||||
starts the logic, draw and event handler
|
starts the logic, draw and event handler until you use basalt.stopUpdate
|
||||||
````lua
|
````lua
|
||||||
local mainFrame = basalt.createFrame("myFirstFrame"):show()
|
local mainFrame = basalt.createFrame("myFirstFrame"):show()
|
||||||
basalt.startUpdate()
|
basalt.autoUpdate()
|
||||||
````
|
````
|
||||||
**args:** -<br>
|
**parameters:** -<br>
|
||||||
|
**returns:**-<br>
|
||||||
|
|
||||||
|
## basalt.update
|
||||||
|
calls the basalt.update method once
|
||||||
|
````lua
|
||||||
|
local mainFrame = basalt.createFrame("myFirstFrame"):show()
|
||||||
|
basalt.autoUpdate()
|
||||||
|
````
|
||||||
|
**parameters:** string event, ... (you can use some paramters here. you dont have to pass any paramters )<br>
|
||||||
**returns:**-<br>
|
**returns:**-<br>
|
||||||
|
|
||||||
## basalt.stopUpdate
|
## basalt.stopUpdate
|
||||||
@@ -57,107 +66,13 @@ stops the logic, draw and event handler
|
|||||||
````lua
|
````lua
|
||||||
basalt.stopUpdate()
|
basalt.stopUpdate()
|
||||||
````
|
````
|
||||||
**args:** -<br>
|
**parameters:** -<br>
|
||||||
**returns:**-<br>
|
**returns:**-<br>
|
||||||
|
|
||||||
## basalt.debug
|
## basalt.debug
|
||||||
Something you just need as a developer, why shouldn't i publish it? This creates a label on the bottom left of your active frame, if you click on that label it will
|
creates a label with some information on the main frame on the bottom left, if you click on that label it will open a log view for you see it as the new print for debugging
|
||||||
create a fully sized frame with a list, where it logs all your debug messages
|
|
||||||
````lua
|
````lua
|
||||||
basalt.debug("Hi i am cute")
|
basalt.debug("Hi i am cute")
|
||||||
````
|
````
|
||||||
**args:** ... (multiple args are possible, like print does)<br>
|
**parameters:** ... (multiple parameters are possible, like print does)<br>
|
||||||
**returns:**-<br>
|
**returns:**-<br>
|
||||||
|
|
||||||
# Tipps
|
|
||||||
If you are new to such things, you want to create your own logic (lets say for example a redstone or rednet handler) while using the basalt Framework, you just have to create something like this:
|
|
||||||
|
|
||||||
````lua
|
|
||||||
local basalt = dofile("basalt.lua")
|
|
||||||
|
|
||||||
local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame and a button without functionality
|
|
||||||
mainFrame:addButton("aButton"):onClick(function() end):show()
|
|
||||||
|
|
||||||
local function yourCustomHandler()
|
|
||||||
while true do
|
|
||||||
-- add your logic here
|
|
||||||
os.sleep(1) -- you need something which calls coroutine.yield(), yes os.sleep does that os.pullEvent() aswell
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
parallel.waitForAll(basalt.startUpdate, yourCustomHandler) -- here it will handle your function (yourCustomHandler) and basalts handlers at the time
|
|
||||||
````
|
|
||||||
You can read [here](http://www.computercraft.info/wiki/Parallel_(API)) what exactly parallel.waitForAll() does
|
|
||||||
|
|
||||||
# Installer
|
|
||||||
Here is a premade installer you can add into your script if you want:
|
|
||||||
|
|
||||||
This is a visual version, it asks the user if he wants to install basalt.lua (if not found)<br>
|
|
||||||

|
|
||||||
````lua
|
|
||||||
--Basalt configurated installer
|
|
||||||
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
|
|
||||||
if not(fs.exists(filePath))then
|
|
||||||
local w,h = term.getSize()
|
|
||||||
term.clear()
|
|
||||||
local _installerWindow = window.create(term.current(),w/2-8,h/2-3,18,6)
|
|
||||||
_installerWindow.setBackgroundColor(colors.gray)
|
|
||||||
_installerWindow.setTextColor(colors.black)
|
|
||||||
_installerWindow.write(" Basalt Installer ")
|
|
||||||
_installerWindow.setBackgroundColor(colors.lightGray)
|
|
||||||
for line=2,6,1 do
|
|
||||||
_installerWindow.setCursorPos(1,line)
|
|
||||||
if(line==3)then
|
|
||||||
_installerWindow.write(" No Basalt found! ")
|
|
||||||
elseif(line==4)then
|
|
||||||
_installerWindow.write(" Install it? ")
|
|
||||||
elseif(line==6)then
|
|
||||||
_installerWindow.setTextColor(colors.black)
|
|
||||||
_installerWindow.setBackgroundColor(colors.gray)
|
|
||||||
_installerWindow.write("Install")
|
|
||||||
_installerWindow.setBackgroundColor(colors.lightGray)
|
|
||||||
_installerWindow.write(string.rep(" ",5))
|
|
||||||
_installerWindow.setBackgroundColor(colors.red)
|
|
||||||
_installerWindow.write("Cancel")
|
|
||||||
else
|
|
||||||
_installerWindow.write(string.rep(" ",18))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
_installerWindow.setVisible(true)
|
|
||||||
_installerWindow.redraw()
|
|
||||||
while(not(fs.exists(filePath))) do
|
|
||||||
local event, p1,p2,p3,p4 = os.pullEvent()
|
|
||||||
if(event=="mouse_click")then
|
|
||||||
if(p3==math.floor(h/2+2))and(p2>=w/2-8)and(p2<=w/2-2)then
|
|
||||||
shell.run("wget https://raw.githubusercontent.com/NoryiE/Basalt/master/basalt.lua "..filePath)
|
|
||||||
_installerWindow.setVisible(false)
|
|
||||||
term.clear()
|
|
||||||
break
|
|
||||||
end
|
|
||||||
if(p3==h/2+2)and(p2<=w/2+9)and(p2>=w/2+4)then
|
|
||||||
_installerWindow.clear()
|
|
||||||
_installerWindow.setVisible(false)
|
|
||||||
term.setCursorPos(1,1)
|
|
||||||
term.clear()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
term.setCursorPos(1,1)
|
|
||||||
term.clear()
|
|
||||||
end
|
|
||||||
|
|
||||||
local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt
|
|
||||||
------------------------------
|
|
||||||
````
|
|
||||||
|
|
||||||
Here is a very basic one which just installs basalt.lua if don't exist:
|
|
||||||
````lua
|
|
||||||
--Basalt configurated installer
|
|
||||||
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
|
|
||||||
if not(fs.exists(filePath))then
|
|
||||||
shell.run("wget https://raw.githubusercontent.com/NoryiE/Basalt/master/basalt.lua "..filePath)
|
|
||||||
end
|
|
||||||
local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt
|
|
||||||
|
|
||||||
````
|
|
||||||
Reference in New Issue
Block a user