PDA

View Full Version : Multiple console commands in a menu



mothphil
09-06-2010, 03:57 AM
i used the scaleform video on youtube to create my menu but the problem is that i can only open one command. currently i have one clik button which opens a map, and the other click button is meant to exit the game. the only one which works at the moment is the map command. heres the code if anyone needs it:

var GFxClikWidget SecretBaseButton;
var GFXClikWidget ExitButton;

/** Callback when a CLIK widget with enableInitCallback set to TRUE is initialized. Returns TRUE if the widget was handled, FALSE if not. */
event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
{
switch(WidgetName)
{
case ('SecretBaseButton'):
SecretBaseButton = GFxClikWidget(Widget);
SecretBaseButton.AddEventListener('CLIK_press', OnSecretBasebuttonPress);
break;
default:
break;
}
return true;

switch(WidgetName)
{
case ('ExitButton'):
ExitButton = GFxClikWidget(Widget);
ExitButton.AddEventListener('CLIK_press', OnExitButtonPress);
break;
default:
break;
}
return true;
}


function OnSecretBasebuttonPress(GFxClikWidget.EventData ev)
{
ConsoleCommand("open DF-SecretBase_P");
}


function OnExitButtonPress(GFxClikWidget.EventData ev)
{
ConsoleCommand("exit");
}

defaultproperties
{
WidgetBindings.Add((WidgetName="SecretBaseButton",WidgetClass=class'GFxClikWidget'))
WidgetBindings.Add((WidgetName="ExitButton",WidgetClass=class'GFxClikWidget'))
}

GeekyPayback
09-06-2010, 05:10 AM
Ok. Breaking down your code



//This is a switch statement, which means that it runs which ever bit of code matches the Widget name.
//If it doesnt find one that matches, it runs the default code;
switch(WidgetName)
{
case ('SecretBaseButton'):
SecretBaseButton = GFxClikWidget(Widget);
SecretBaseButton.AddEventListener('CLIK_press', OnSecretBasebuttonPress);
break;
default:
break;
}

// This line exits the function - THIS IS YOUR PROBLEM
return true;

//This is a switch statement, which means that it runs which ever bit of code matches the Widget name.
//If it doesnt find one that matches, it runs the default code;
switch(WidgetName)
{
case ('ExitButton'):
ExitButton = GFxClikWidget(Widget);
ExitButton.AddEventListener('CLIK_press', OnExitButtonPress);
break;
default:
break;
}

// This line exits the function
return true;


Hopefully you can see now that the reason your code only runs the map loading command (because you have a return true command after the first switch).
Removing it will make your code run correctly, but you've still missed the point of the switch statement. Heres how it should be written -



//This is a switch statement, which means that it runs which ever bit of code matches the Widget name.
//If it doesnt find one that matches, it runs the default code;
switch(WidgetName)
{
case ('SecretBaseButton'):
SecretBaseButton = GFxClikWidget(Widget);
SecretBaseButton.AddEventListener('CLIK_press', OnSecretBasebuttonPress);
break;
case ('ExitButton'):
ExitButton = GFxClikWidget(Widget);
ExitButton.AddEventListener('CLIK_press', OnExitButtonPress);
break;
default:
break;
}

// This line exits the function
return true;

mothphil
09-06-2010, 12:43 PM
Thanks for that. and i do understand what i was doing wrong. im just getting into coding and i tried looking at the scaleform page for help but obviously couldn't find the answer.