Pretty straight forward question, I’ve just forgotten the correct coding to do it. I have a void set up and I want it to run when I click a button.
Void I want executed:
public void giveWeapon(int clientIndex, string weaponName)
{
uint guns = getWeaponId(weaponName);
XDRPCExecutionOptions options = new XDRPCExecutionOptions(XDRPCMode.Title, 0x822728F8); //Updated
XDRPCArgumentInfo<uint> info = new XDRPCArgumentInfo<uint>(getPlayerState(clientIndex));
XDRPCArgumentInfo<uint> info2 = new XDRPCArgumentInfo<uint>((uint)guns);
XDRPCArgumentInfo<uint> info3 = new XDRPCArgumentInfo<uint>((uint)0);
uint errorCode = xbCon.ExecuteRPC<uint>(options, new XDRPCArgumentInfo[] { info, info2, info3 });
iprintln("gave weapon: " + (guns.ToString()));
giveAmmo(clientIndex, guns);
//switchToWeapon(clientIndex, 46);
}
And I just want it to run on button click:
private void button14_Click(object sender, EventArgs e)
{
// Call void here
}
voidis a keyword indicating that your functiongiveWeapondoes not return a value. So your correct question would be: “How can I call a function?”The answer:
if
giveWeaponis defined in a different class, you’d need to create an instance and call the method on that instance, i.e.:As a side note, your code readability would benefit a lot from using implicitly typed local variables: