You must login before being able to do this action

Haxe Forum > Optional parameters help

  • Hi, I'm porting some AS3 code to Haxe and am stuck trying to get this code to compile:

    //in the _log class
    public function formatOutcomeNode(charID:String, team:String, ?hpDelta:Int, ?apDelta:Int, ?xpDelta:Int, ?status:String, ?loot:String):Xml
    
    //elsewhere...
    _log.formatOutcomeNode(_character.id, _character.teamName, delta);    //error: Function 'formatOutcomeNode' requires arguments : charID, team, ?hpDelta, ?apDelta, ?xpDelta, ?status, ?loot

    This seems like it should work according to this documentation: http://haxe.org/ref/optional_args

    What am I doing wrong?

  • Aha, figured it out right after posting. I was passing 'delta' as a Float instead of an Int. I've been spoiled by AS3 coercing Numbers and ints fluidly on my behalf.

  • You can reread this lesson http://haxe.org/ref/optional_args .

< Prev | Page 1 / 1 | Next >