• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Problem compiling KF2Bots mutator

jacktyme

FNG / Fresh Meat
Jan 24, 2017
2
0
45
Hello, I want to use KF2Bots mutator on my server. I know its not whitelisted, but I need it to test out something else which has really nothing to do with KF 2 but more about Steams server browser list.

you can find the src here:http://forums.tripwireinteractive.c...-ad/beta-mod-releases/117954-mutator-kf2-bots

I'm trying to compile it and i get this error: 'function CanReload' differs from original; different number of parameters

I know a little C# and I can tell that to fix this is really easy, but I don't have sufficient coding knowledge to fix it.

I tried adding a bool variable inside the brackets: CanReload(bool "var") I get the same error but without the "different number of parameters" message.

If anyone has the time to help me out i'd really appreciate it.
 
The issue is that the function definition (the name of the function and the number and type of parameters) does not match that of the function you're trying to override. CanReload() doesn't have any parameters, so when you override it, you can't just add new parameters to it. You also can't change the type of them. There are several ways to get around this problem that I know of.

1. Create a new function, with the following function definition CanReloadNew(bool SomeBool), for example. Fill this function with the logic you want, perhaps with no code taken from CanReload(), perhaps matching it almost exactly. Then, wherever CanReload() is normally called and you want your modified version to be called instead, replace the call to CanReload() with a call to CanReloadNew(SomeBool). This might require extending a lot of classes to replace the function calls to CanReload(). That's just the way it is sometimes.

2. Declare an instance variable in the class that you're overriding CanReload(). This variable should be of the type that you would've passed into CanReload() if you could've added extra parameters - in your case a bool. So towards the top of the class above nay functions, you'd have:
Code:
var bool SomeBool;
Override CanReload(), and inside the logic of the function, use this instance variable SomeBool as if it was a local variable for this function. Actually setting this variable to the desired value now must be handled separately from the function call.

3. Instead of calculating the value of the bool before passing it into the function as a parameter, define a local bool inside CanReload() and figure out the correct value within the function.

There are probably many more options, but these are the ones I could think of off the top of my head, and that I have used before. There are pros and cons of each method, so you'll have to decide which is most suitable in each circumstance.

If you're still having trouble with it, tell me what you're trying to achieve and I'll try to suggest the most appropriate solution to your specific problem.

PS: Just a heads up, var is a keyword in Unrealscript, so don't use it as a variable name. Also, don't put variable names in quotes otherwise the compiler will see them as string literals, not as a variable.
 
Upvote 0
Also keep in mind, sometimes twi redefines functions in updates and you don't know until you go to compile code. What once worked, may not work afterwards. Track down where "CanReload()" is defined and make sure your code is defined exactly the same. When you extend a class in unrealscript, you inherit the class you extend. Which inherits the class it extended.. and so on. Somehwere down the line "CanReload()" was defined differently than your class.
 
Upvote 0