Im editing strazer's character control module for my own purposes, and I'm trying to add new function to module. But i have problems using optional parameters.
Im importing function in module's header like this:
struct CharacterControl {
import static function CreateChain(int chainid, String commandstring);
import static function AppendChain(int chainid, String commandstring);
import static function GetChain(Character *thechar);
import static function GetChainPosition(Character *thechar);
import static function GetRoom(Character *thechar);
import static bool IsExecuting(Character *thechar);
import static bool IsPaused(Character *thechar);
import static function PauseExecuting(Character *thechar);
import static function ResumeExecuting(Character *thechar);
import static function StartExecuting(Character *thechar, int chainid, int chainposition=1);
import static function StopExecuting(Character *thechar);
import static function SetNewChain(short mainchainid,short subchainid, int subchainposition=1, int WhoExecutes =-1);
};
My function is the last one (SetNewChain)
And at module script I'm using it like this:
static function CharacterControl::SetNewChain(short mainchainid, short subchainid, int subchainposition, int WhoExecutes) {
CharacterControl_NewChain(null, String.Format("%d", subchainid));
CharacterControl.CreateChain(mainchainid, NewChain);
if (WhoExecutes != -1) CharacterControl.StartExecuting(character[WhoExecutes], mainchainid, subchainposition);
}
The problem is that when i use function whitout setting value to optional parameter 'WhoExecutes', if-command at the last line of script is executed even WhoExecutes value should be at -1?
And what is its value then?
You can check it with a Display call just before the if-check:
Display( "WhoExecutes = %d", WhoExecutes );
if (WhoExecutes != -1) ...
Quote from: Scorpiorus on Mon 17/09/2007 20:42:16
And what is its value then?
You can check it with a Display call just before the if-check:
Display( "WhoExecutes = %d", WhoExecutes );
if (WhoExecutes != -1) ...
First place where i call the function gives -1 as it should be.
Second place gives a random value near 34000000 ::)
EDIT:
First place is inside other function at the "first time player enters the room"-script of the first room.
second place is at room's "use object" script.
But i cant find any reason why different position in script should affect to 'WhoExecutes' value.
Im using AGS2.8beta9 in case it could be a bug in the editor.
Can you post the exact lines of the function calls in those two places in question?
I have a feeling that I may know the reason for it but it doesn't account for the different behaviour at different calls.
First place:
CharacterControl.SetNewChain(chr[counter].chainnumber, chr[counter].chainsubnumber);
Second:
CharacterControl.SetNewChain(chr[1].chainnumber, 31);
in both calls paramerer1's value is 2 and at first call parameter2's value is 30
Hmmm. Odd.
Try changing the default value to some other numbers like say, 12. Do the two calls print different values.
With different values, first function call gives the right value and second gives a randomnumber near 34000000 like before.
I also tried "Display ("%d",subchainposition);" (The third parameter in function) and that gives right value at first call, and value 0 at second call.
Then i erased subchainposition, and whoexecutes started to give value 0 at second call.
So it seems that 3. parameter of function gives always 0 and 4th gives that 34000000. I also added 5th parameter witch always gives 501. ???
Hmm... that does seem rather odd. Unfortunately I can't check it myself at the moment, so I don't know if it's a new AGS 2.8 beta's specific issue.
What if you re-declare function parameters as "int" instead of "short", does it make any difference at all?
import static function SetNewChain(int mainchainid, int subchainid, int subchainposition=1, int WhoExecutes =-1);
Quote from: Scorpiorus on Sun 23/09/2007 18:50:42
Hmm... that does seem rather odd. Unfortunately I can't check it myself at the moment, so I don't know if it's a new AGS 2.8 beta's specific issue.
What if you re-declare function parameters as "int" instead of "short", does it make any difference at all?
import static function SetNewChain(int mainchainid, int subchainid, int subchainposition=1, int WhoExecutes =-1);
Yes, :)
Parameters started to give right values when i did it. It seems like a bug in the editor to me.
Did you rebuild the room after adding the optional parameters? If not, the room won't have been recompiled to pass in the new default values.
Try a Rebuild All Rooms and see if that sorts out the problem.
Quote from: Pumaman on Tue 25/09/2007 19:52:05
Did you rebuild the room after adding the optional parameters? If not, the room won't have been recompiled to pass in the new default values.
Try a Rebuild All Rooms and see if that sorts out the problem.
Yes, i rebuilt all files and that solved it :)
Glad to hear it :)
This does make me wonder whether perhaps AGS should automatically rebuild all room files whenever you change a script header...
Or it could ask wheter rebuild or not.
Maybe if it said something to the effect of "You have just modified a script header. Any changes will not be reflected by your room scripts until the rooms are rebuilt. Do you wish to rebuild now?"
Now that CJ pin-pointed the problem I remember having similar issues in the past myself.
Quote from: Pumaman on Tue 25/09/2007 23:39:55
This does make me wonder whether perhaps AGS should automatically rebuild all room files whenever you change a script header...
I vote for that. I almost got in trouble with that making my last game... could easily have overlooked it and just happened to see the Rebuild all Rooms link and thought "I bet I need to do that".
On modern computers, rebuilding all the rooms goes pretty fast.
I think an optional rebuid would be a good idea, since often the script header is edited in terms of extending (meaning adding more new stuff) rather than modifing existing declarations.