x


Button list from array

I want to create a list of buttons from an array, with for each button a texture, but how can i place buttons, with each a specific position and it's own texture and values from an array. The whole idea behind this is to create some kind of app drawer for windows, so each button has to open a specific program on the computer. If anyone has an idea about this. please let me know

more ▼

asked Jan 16 '12 at 03:31 PM

Raymond 2 gravatar image

Raymond 2
149 39 40 45

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

If you're generating buttons in a pattern, you can use for loops. Example:

function OnGUI(){
    for (var 1 : int = 0; i <= yourArray.length; i++){
        yourArray[i] = GUI.Button(Rect(10*i,0,10,10),image[i]);
        if (yourAray[i]){
            //Your code here
        }
    }
}

This will mass create and check buttons in each array item. It's important to say that yourArray will hold the buttons (boolean value), not their content. Just put your code in the defined spade and you're done. P.S.: This example will create a row of buttons. It's recommendable that you use a grid generator intead if you plan to display multiple rows (that's very easy to find).

image is the array of icons for your buttons. You can also use text if youd efine as a String array.

more ▼

answered Jan 16 '12 at 03:53 PM

Kroltan gravatar image

Kroltan
74 11 11 15

(comments are locked)
10|3000 characters needed characters left

Just create a struct with two public members ("Rect buttonRect" and "Texture buttonTexture"), finally declare the list object as array of your struct

more ▼

answered Jan 16 '12 at 03:47 PM

SkaredCreations gravatar image

SkaredCreations
571 1 2

but how can it place the buttons then? :S still a noob in GUI scripting:P

Jan 16 '12 at 03:52 PM Raymond 2

sorry i put it as answer, always forget that i can comment

Jan 16 '12 at 03:52 PM Raymond 2

This is my current script, how could i edit this so that the buttons link to the different applications, then i would be happy already if i know that.

import System.Diagnostics;

var stringPath = "../";

//All icon textures

var btnTexturePS : Texture;

//All application links

var appLink : String[];

var selGridInt : int = 0;

var selStrings : String[] = ["Grid 1", "Grid 2", "Grid 3", "Grid 4"];

function OnGUI () {

selGridInt = GUI.SelectionGrid (Rect (25, 25, 200, 50), selGridInt, selStrings, 2);

}

Jan 16 '12 at 03:54 PM Raymond 2

Excuse me, but are you using C# or JS? You imported something, that's from C#, but the variable definitons look like JS.

Jan 16 '12 at 04:02 PM Kroltan

i write in JS, but the cde works fine so it seems it's JS, and as far as i see, it's written as JS

Jan 16 '12 at 04:05 PM Raymond 2
(comments are locked)
10|3000 characters needed characters left

I just gave someone else an example of creating a grid of buttons from a multidimentional array on this question... Infect the blank cubes

Take a look at it. It might me of some help to you as well.

-Larry

more ▼

answered Jan 16 '12 at 08:19 PM

Larry Dietz gravatar image

Larry Dietz
532 9 14 23

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1881
x1133
x717
x21

asked: Jan 16 '12 at 03:31 PM

Seen: 2393 times

Last Updated: Jan 16 '12 at 11:35 PM