Jump to content

help


Recommended Posts

Posted

code : 

itemDef_t CreateItem(menuDef_t *menu, int type){
	itemDef_t *item;
	if (menu->itemCount < MAX_MENUITEMS) {
		menu->items[menu->itemCount] = (itemDef_t *)BG_Alloc(sizeof(itemDef_t));
		item = menu->items[menu->itemCount];
		Item_Init(item);
		item->type = type;
		item->id = menu->itemCount;
		item->parent = menu;
		Item_InitControls(item);
		item->parent = menu;
		menu->itemCount++;
		Com_Printf("ITEMID %d", item->id);
		return *item;
	}
}

The idea is that every time I call this function for a specific menu, it should increase menu->menuCount by 1, but this is not happening. Why?

Posted

I don't know how the menu code functions AT ALL, but I'm guessing you're not passing a local variable menuDef_t to that function.

If you're passing a menuDef_t* (pointer) then you'd need to do some shit like

itemDef_t CreateItem(menuDef_t **menu, int type)

then pass it as

CreateItem(&menu, type); or whatever.

Ooooor you can just pass a pointer to menu->ItemCount if that's the only thing that needs to change. So it'd become...

itemDef_t CreateItem(menuDef_t **menu, int type, int *ItemCount)
{
...
*ItemCount++;
}

But yeah someone correct me if I'm over-complicating this.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...