PDA

View Full Version : Delegate Assignment Failed?



caudex
05-10-2007, 10:21 PM
God this error is getting so annoying...............
Keeps saying XInterface.GUIButton: Delegate Assignment Failed.

Kinda getting on my nerves.... the Menu works 100% perfectly... i change a value of the Name of a button... then it brings up that error... ctrl+z to undo that name change... and it still gives me that error... Where does the error come from?

The error is hooking at OnClick=InternalOnClick

I never even changed the Onclick, only thing i changed was the Name of the button.

Code of one of the buttons:


Begin Object Class=GUIButton Name=ExitMenu
Caption="Exit Menu"
WinWidth=0.2
WinHeight=0.04
WinLeft=0.65
WinTop=0.75
bBoundToParent=true
OnClick=InternalOnClick
End Object
Controls(3)=GUIButton'ExitMenu'


Heres my internalonclick

function bool InternalOnClick(GUIComponent Sender)
{
P = PlayerOwner().Pawn;
if (Sender==Controls[1])
{
P.GiveWeapon("xweapons.RocketLauncher");
P.ClientMessage("You have bought Rocket Launcher");
}
if (Sender==Controls[2])
{
P.GiveWeapon("xweapons.flakcannon");
P.ClientMessage("You have bought Flak Cannon");
}
if (Sender==Controls[3])
{
P.GiveWeapon("xweapons.SniperRifle");
P.ClientMessage("You have bought Sniper Rifle");
}
else
Controller.CloseMenu(false);

return false;
}

But im pretty sure that code is correct

SuperApe
05-11-2007, 09:15 AM
It looks correct on first glance.

This from UnrealWiki:
Delegate assignment failed
You tried to assign a function to a delegate property, but the function's parameters and/or return value don't match the delegate's parameters and/or return value.

But, I see your return value is there, those are the OnClick arguements. Hmm...

The only thing I see that's different from what I work with is you've set the button to "Controls[x]", instead of defining a separate GUIButton variable name, like
var GUIButton Button1, Button2, Button3;. Maybe try that. :confused: The only other thing I can think of is to double-check the other buttons.

Wormbo
05-11-2007, 10:46 AM
Sometimes the compiler simply refuses to assign delegates in defaults for no obvious reasons. In such a case you could assign the delegate in InitComponent(), which should always work.

caudex
05-11-2007, 07:07 PM
If i assign the delegate in InitComponent how would i be able to declare the Control()?

ghouck
05-21-2007, 12:08 AM
Isn't having numbers in variable names a no-no?