anything related to UI in general, splash screens, UI widgets, input and output etc.

Creating GUI elements from script

Creating GUI elements from script

Postby planetX » 27 Dec 2017, 10:11

Hi There,

I'm working on an interface and want to create some items in runtime. I have a <div> which is the container, and I want to create the items inside that container. The markup would look similar to this:

Code: Select all
<div id="container">
   <div></div>  <-- these are the elements I want to create
   <div></div>
   ...
</div>


And this is the Lua script. I'm taking the elements from an array:

Code: Select all
function ShowItems()
   local strItem = 0
   for i=1,total_items,1 do
      strItem = "<div class=\"element\">"
      strItem = strItem.."<div class=\"icon\">"
      strItem = strItem.."<div class=\"thumb "..items[i]["image"].."\"></div>"
      strItem = strItem.."</div>"
      strItem = strItem.."<div class=\"amount\">"
      strItem = strItem.."<div class=\"have\">"..items[i]["amount"].."</div>"
      strItem = strItem.."</div>"
      strItem = strItem.."</div>"
      gui.setText( GUI_ID , "container", strItem )
   end   
end


The problem is that I only get one item in the screen, although in the console I get it printed several times (= total_items).

How can I create all the items?

Thanks in advance!

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Mage
 
Posts: 210
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: Creating GUI elements from script

Postby planetX » 06 Jan 2018, 08:36

Nevermind, I finally managed to solve it. I was replacing the variable at every loop, so all I had to do is concatenate the strings and get the gui.setText() out of the loop.

Code: Select all
function ShowItems()
   local strItem = ""
   for i=1,total_items,1 do
      strItem = strItem.."<div class=\"element\">"
      strItem = strItem.."<div class=\"icon\">"
      strItem = strItem.."<div class=\"thumb "..items[i]["image"].."\"></div>"
      strItem = strItem.."</div>"
      strItem = strItem.."<div class=\"amount\">"
      strItem = strItem.."<div class=\"have\">"..items[i]["amount"].."</div>"
      strItem = strItem.."</div>"
      strItem = strItem.."</div>"
   end   
   gui.setText( GUI_ID , "container", strItem )
end

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Mage
 
Posts: 210
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: Creating GUI elements from script

Postby SolarPortal » 08 Jan 2018, 12:42

glad you got that fixed and sorry for the delay in response, only got back onto the dev machine today :)
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3202
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer


Return to UI

Who is online

Users browsing this forum: No registered users and 1 guest