Advertisement

Default Parameters

Started by May 02, 2004 07:05 AM
2 comments, last by meink 20 years, 6 months ago
Is it possible to define default parameters for angelscript functions? I''ve tried defining both: CParticle* createParticle(float, float) CParticle* createParticle(float, float, bstr) Both point to the same C Function, which has a default value set for the last parameter. I can call the latter, but the former results in confusion about which function to call. I also tried: CParticle* createParticle(float, float, bstr="") But it didn''t like that at all. I couldn''t find anything about this in the documentation or the sample code. Is this deliberate behaviour, something I''ve missed, or a bug? - Xavier
Default arguments are not part of the language... You can''t just leave out one of the arguments are expect the default to be applied because it is AngelScript that is pushing the arguments onto the stack- if you leave one off, then that argument isnt on the stack when the function gets executed. I''m not an expert on how the stack works with regards to passing arguments, but I would assume that if AngelScript didnt push all the proper data, then the function you called would be interpreting some random data as the last argument...
Advertisement
Desdemona is correct.

In C/C++ you are allowed to define default parameters for functions, but these default parameters doesn''t really change the function interface. It''s just that the compiler fills in the missing parameters for you. The parameters are still sent to the function.

When you register a function with AngelScript you have to declare all of the parameters, even those that have default arguments, otherwise AngelScript won''t push the correct amount of data on the stack, resulting in random behaviour.

Currently AngelScript doesn''t allow you to define default parameters for function calls, but I might consider it for a future version.



__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

OK, thanks for your help.

- Xavier

This topic is closed to new replies.

Advertisement