Hey,
I'm wondering if there is a way to use an optional parameter in a function which checks if an animation runs as blocked or not, I'm currently checking which character ID has been passed into the function and then using a "if/else" check.
function animate(int id, String saybg, int struct_id1, int struct_id2)
{
if (character[id].Loop == 0 || character[id].Loop == 2 || character[id].Loop == 4 || character[id].Loop == 5) {
if (id == player.ID) {
character[id].Animate(8, 4, eOnce, eBlock);
//
}
else {
character[id].Animate(8, 4, eOnce, eNoBlock);
}
}
My goal would be to replace the eBlock/eNoblock with the parameter and get rid of the id check.
on the header, you can import the function and declare the optional values there using the equal sign.
How do i declare the optional value for eBlock/eNoBlock is it a bool?
in header:
import function animate(int id, String saybg, int struct_id1, int struct_id2, BlockingStyle block = eBlock);
in script:
function animate(int id, String saybg, int struct_id1, int struct_id2, BlockingStyle block)
{
character[id].Animate(8, 4, eOnce, block);
}
Oh there we go, i didn't know about BlockingStyle, brilliant!, thank you eri0o and Crimson as all ways :-)
https://adventuregamestudio.github.io/ags-manual/StandardEnums.html#blockingstyle
Quote from: Crimson Wizard on Mon 22/08/2022 00:04:54
in header:
import function animate(int id, String saybg, int struct_id1, int struct_id2, BlockingStyle block = eBlock);
in script:
function animate(int id, String saybg, int struct_id1, int struct_id2, BlockingStyle block)
{
character[id].Animate(8, 4, eOnce, block);
}
Just to go a little bit deeper into this, i already have optional parameters in the function such as:
import function animate(int, String saybg = 0, int = -1, int = -1);
I'm assuming the BlockingStyle should be the first optional parameter check as it takes precedence over the other optional parameters.
Edit: i see from your post you're naming the optional variables as they where declared, is this necessary or am i going to get a horrible bug for not doing so?
Quote from: Pax Animo on Mon 22/08/2022 00:22:36
I'm assuming the BlockingStyle should be the first optional parameter check as it takes precedence over the other optional parameters.
Well, that's purely a question of convenience, but all the optional parameters must be after non-optional ones.
Quote from: Pax Animo on Mon 22/08/2022 00:22:36
Edit: i see from your post you are naming the optional variables as they where declared, is this necessary or am i going to get a horrible bug for not doing so?
No, names in import declaration and in function definition may be different.
One thing that I'd mention is that not giving any name at all means whoever uses this function won't know what these parameters mean (and script editor won't show their names in a hint).
Quote from: Crimson Wizard on Mon 22/08/2022 01:28:48
One thing that I'd mention is that not giving any name at all means whoever uses this function won't know what these parameters mean (and script editor won't show their names in a hint).
Oh yeah, i did notice that i had to check on a few occasions what an optional parameter was used for as it just showed "int/bool and so on" in the editor hint.
Your mention clears up that question nicely, thanks again.
I also didn't know that the "e"Block was a enum, my knowledge of AGS has levelled up :-)
Quote from: Pax Animo on Mon 22/08/2022 01:43:19
I also didn't know that the "e"Block was a enum, my knowledge of AGS has levelled up :-)
For the information, there's a list of all enums in the manual:
https://adventuregamestudio.github.io/ags-manual/StandardEnums.html