Eachin is not by reference?

About Monkey 2 Forums Monkey 2 Development Eachin is not by reference?

Tagged: 

This topic contains 5 replies, has 4 voices, and was last updated by  doaqwh 2 years, 3 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #6254

    Diffrenzy
    Keymaster

    I find it confusing that Eachin seems to work on a copy of my collection and not looping through it as I expect it to, like it does im monkey-x and c#

    Is this intended behaviour, and where do I read about it?

    Example:

    #6257

    codifies
    Participant

    looks like you’re changing a local variable p not items in points…

    see the Icontainer “interface” documentation, it shows you the code eachin gets converted into.

    #6258

    Diffrenzy
    Keymaster

    looks like you’re changing a local variable p not items in points…

    Yes, that’s what going on. However this Monkey-x code treats the p as a reference:

     

    #6262

    nerobot
    Participant

    The difference (not your nickname:) ) is: in mx2 vec2f is a struct but it is a class in mx1. struct is copied when assign it to var.

    If you define vector as a class in mx2 it will be changed by the way you shown above.

    #6264

    Diffrenzy
    Keymaster

    Thanks nerobot. That makes sense, and explains the behaviour.

    #6269

    doaqwh
    Blocked

    Would you like to be friends with me?

    Can we be friends?

    RS Gold to you at http://www.rsgoldfast.com/

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.