Druid's Progress bar - register, initialise

Spent most of a day on this and still have nothing to show for it. I wanted to create a progress bar with the code sample from the Druid HTML/Gith page - put the code in a new .lua file, reference it in the GUI script. The editor tells me to register the extended component. I try this:
local progress = require(“druid.extended.progress”)
druid.register(“progress”, progress)

which I can only hope is correct. I then struggle to construct the line for the init function (don’t laugh - I am a bloody beginner). Happy to provide my code/project for anyone willing to help me out.

It’s not only you, I often got questions about how to use examples and something about druid.register. I think I should rework it a little to make it much more user friendly

Currently it means that you need to add this lines of code somewhere in your initial collection to add this component inside your game build

local druid = require("druid.druid")
local progress = require("druid.extended.progress")

function init(self)
    druid.register("progress", progress) -- After this line the `self.druid:new_progress` is available
end

After this done, you able to create progress component anywhere in you GUI. So now you need to add the GUI box node at scene, which will be used as a progress node (it’s size will be manages by progress components) and create the progress component itself

-- Inside GUI script
local druid = require("druid.druid")

function init(self)
    self.druid = druid.new(self)
    -- Pass "x" if horizontal, "y", is vertical
    self.progress = self.druid:new_progress("progress_node_id", "x")

    -- Now you can call progress component functions
    self.progress:set_to(0.5)
end

It will looks like the progress example (druid/example/examples/basic/progress_bar/basic_progress_bar.lua at develop · Insality/druid · GitHub) but druid.register already done in the loader collection and whole example code is a Druid custom component intead of gui_script as I provided

2 Likes

Ah, I never thought about adding the register line to the init function. It works now, thank you.
Druid is cool - for a beginner like me with many noob issues, an explanation as if taught to a five-year-old would be fantastic, there are quite a few points that I still wonder about and find less than clear from the GitHub page.
Thanks!

1 Like