data from list box

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
circusdan
Posts: 32
Joined: Thu Jun 02, 2011 10:05 pm
Location: United States

data from list box

Post by circusdan »

I need to get data from a list box, there are 3 choices in it, and i would like to get preferably an integer representing each choice, such as 1, 2, or 3. I think im supposed to use getIcon() but I cant for the life of me figure out how. Any ideas?
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

There's this function with a pretty descriptive name called

Code: Select all

getSelected()
It'll return the id of the - boing! - currently selected choice based on the ID you got returned calling

Code: Select all

addItem()
when filling it.

Please, always have a look at the documentation first.

Cheers,
p.
beer->setMotivationCallback(this);
circusdan
Posts: 32
Joined: Thu Jun 02, 2011 10:05 pm
Location: United States

Post by circusdan »

I always start with the documentation before i end up posting, its just alot to go through and I dont always find it, thanks. That returns an s32, I made a function that wouldnt take that, so i just made it an int without converting and it didnt shoot out an error, im still having some issues so Im not sure if it works, can i do that?

heres what I mean, heres the event reciever part with this
case EGET_LISTBOX_CHANGED:
if(id==103)
{
GUIChange = true;
selectedTime = box->getSelected();
}
break;

and heres the function
int listBox(int selectedTime)
{
if(selectedTime == 0)
{
return 10;
}

if(selectedTime == 1)
{
return 6;
}

if(selectedTime == 2)
{
return 15;
}

}
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I don't get it... you can certainly call "box->getSelected();" - but I guess you found that out yourself by now, so that's probably not what you are asking.

Do you want to get the selected text of the listbox?
Or the index of the item (so you can get the text later for example)?
Or a number which has nothing to do with either of them?
Or did you already try something and run into troubles? If so - what's the exact problem?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
circusdan
Posts: 32
Joined: Thu Jun 02, 2011 10:05 pm
Location: United States

Post by circusdan »

I want to get a number representing each item, which i suppose is the index. The index is s32 data type. However, i could only use it in the function as an int. When i change the list box nothing is happening, so im assuming im doing something wrong. I'm pretty sure I have the redraw conditions for the gui right since i did it the same way that i did the resizing redraw, so im pretty sure the listbox stuff just isnt changing when i change the GUI. Is it something to do with using the index as an int?
circusdan
Posts: 32
Joined: Thu Jun 02, 2011 10:05 pm
Location: United States

Post by circusdan »

question aborted. Apparently I'm dumb and can't tell the difference between a list boox and combo box, so i was using EGET_LISTBOX_CHANGED for the combo box reciever
circusdan
Posts: 32
Joined: Thu Jun 02, 2011 10:05 pm
Location: United States

Post by circusdan »

So I'm having a very strange issue. When i change my list box, the data changes appropriately, but the list box still displays that it is set on the first setting, and I cant figure out why. When i had blank data returns for it I didnt have this problem, does anyone know why this would happen?
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Why shouldn't it be set on the first setting when you change the data? Or what would you expect to happen?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
circusdan
Posts: 32
Joined: Thu Jun 02, 2011 10:05 pm
Location: United States

Post by circusdan »

Sorry, combo box. There are 3 choices in the combo box. It is set on the first one by default. Except if i where to change it to the second setting, the data changes, as expected, but the combo box still shows that it is set on the first choice, which it isnt
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I can't reproduce this. When I change the active setting of a combobox it does show the new selected setting.

Maybe you reset it somehow?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
circusdan
Posts: 32
Joined: Thu Jun 02, 2011 10:05 pm
Location: United States

Post by circusdan »

I looked through the whole thing and couldnt see where i might have reset it. Even if i did reset it, im using getIcon() and the data would be stuck on the first setting if it reset, maybe it's a bug in the compiler? Ill go through it more and report back
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

hehe - trust your compiler. But if you post the code of what you are doing someone might be able to help you.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

circusdan wrote:im using getIcon()
so what are you using, a listbox or a combobox ??? :shock:
a combobox has no function callet getIcon() !!! :lol:
also I doubt this is what you want, or do you want to get the icon of an element ??? :roll:
try getSelected()... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
circusdan
Posts: 32
Joined: Thu Jun 02, 2011 10:05 pm
Location: United States

Post by circusdan »

Im using a combo box, I am using getSelected,not getIcon. the code for that is all spread out but ill post it as best as i can.
Heres my reciever:

Code: Select all

	case  EGET_COMBO_BOX_CHANGED:
						if(id==103)
						{
							selectedTime = box->getSelected();
							GUIChange = true;
						}
						break;
Here is a function i use with the combo box information

Code: Select all

int numberOfLobbies(int time, server *object)
{
	int speedVar;
	int x;
	int y;
	int z;

	if(time == 0)
	{
		x = 0;
		for(i=0; i < lobbies; i++)
		{
			speedVar = object[i].getSpeed();
			if(speedVar == 0)
			{
				x++;
			}
				
		}
		return x;
	}

	if(time == 1)
	{
		y = 0;
		for(i=0; i < lobbies; i++)
		{
			speedVar = object[i].getSpeed();
			if(speedVar == 1)
			{
				y++;
			}
				
		}
		return y;
	}

	if(time == 2)
	{
		z = 0;
		for(i=0; i < lobbies; i++)
		{
			speedVar = object[i].getSpeed();
			if(speedVar == 2)
			{
				z++;
			}
				
		}
		return z;
	}

}
Here is where i use the combo box information to set the list box

Code: Select all

 server servers[50];
server object[] = {createServers(servers, _countof(servers))};

IGUIListBox *list = mygui->addListBox(rect<s32>(componantX, componantY, 
					 componantWidth+componantX, componantY+componantHeight), 0, 104);
				 i = 1;
				 while(i <= numberOfLobbies(selectedTime, object))
				 {
					  wCharString = core::stringw(listText.c_str());
					  wCharString += i;
					  list->addItem(wCharString.c_str());
					  i++;
				 }
If you need to see my reciever class and function that creates it I can post that too
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I've edited your post a little - please take a look at those labels above the box where you write your posts. With the code label you can mark code which makes it a lot more readable (you can also see that now when you click "edit" for the post I've changed.

Ok, your code clears up a little confusion - you are not working with one element going wrong, but it seems you have 2 gui-elements - a listbox _and_ a combobox. But now we still don't know what exactly is your problem. What is displayed wrong? The combobox or your listbox? And what exactly is wrong there? And what did you expect to happen if everything would function correctly? You have to realize that we don't see what's happening on your screen - so the only way we can understand what you see and what is going wrong is if you describe it very(!) precisely. Don't hesitate to add screenshots if words are not sufficient - you can use a free image-service like imgur.com to upload screenshots.

I see no obvious bug in your code. Although I can give you a few hints which are unrelated, but might help you in the long run when you do coding:

First you should avoid fixed-sized arrays in c++ (like servers[50]) unless you have a very, very good reason to use them. In 99.9% of all cases you will have an easier life by using a dynamic array like irr::core::array or std::vector (both work in a similar way). Those will catch a lot of accidental bugs you might run into otherwise.

If you ever work with a fixed-size array, then try to avoid using magic-numbers (like 50), but use constants or defines instead. Sooner or later you will change the size and forget it in some other place otherwise.

Then you should make variable-names tell what they are used for - not what type they are. Anyone reading your code can see the type, but a name like wCharString doesn't tell the reader anything, while lobbyName (or wLobbyName if you absolutely want the wchar_t info) would be telling. Same goes for "object" - I guess every programmer once called an object with that name, but as every object is an object you will pretty soon stop calling it like that - so just start now.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply