Import/Includes and globals?

About Monkey 2 Forums Monkey 2 Programming Help Import/Includes and globals?

This topic contains 21 replies, has 7 voices, and was last updated by  Richard Betson 2 years, 6 months ago.

Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #4282

    EdzUp
    Participant

    It seems MonkeyX2 v1.0.5 doesnt like imported classes is there a way of doing the whole thing.

     

    Main.monkey2 looks like

     

    And the ultim class import looks like this

    What im trying to do is include the file in the main source like I could with all the other systems and call Ultim.whatever to call the relevant functions from the Ultim class so if I add a Audio class to the Ultim class that links to another AudioClass class with Audio:AudioClass … then I would use Ultim.Audio.x. This way I can build a framework to use in monkey2 and actually use some of its power.

    I think a tut on including classes from other files would be a brilliant idea as this beasty is a lot different than any other BRL language to date.

    #4283

    impixi
    Participant

    Define a namespace at the top of ultim.monkey2 e.g:

    Namespace ultim

    In your main.monkey2 your import should be:

    #Import "ultim.monkey2"

    and then you need to put the following at the top:

    Using ultim..

    Alternatively, just delete the Namespace defined in main.monkey2 and fix the import statement, as above.

    #4288

    EdzUp
    Participant

    Ah thanks impixi will have a look at that 🙂

    #4290

    abakobo
    Participant

    Here’s a little zip with a working example of multiple imports.
    Runs fine with 1.0.7 but should be ok with earlier versions.

    main:

    [/crayon]

    lib_a

    [/crayon]

    lib_b

    [/crayon]

    lib_c

    [/crayon]

    lib_d

    [/crayon]

    edit:added a global class declared outside of main so use import-1.monkey2

    #4296

    abakobo
    Participant

    Here your code corrected and running..

    [/crayon]

    the Ultim.monkey2

    [/crayon]

    Note that I renamed things called Ultim to Ultimsomething because you can’t have the same for a variable and a namespace/filename.

    #4297

    EdzUp
    Participant

    abakobo: thanks for that im still in newb land with MX2 so it will takke a while for mw to get upto speed but I will persevere with it 🙂

    EDIT: I now have the namespace set to UltimEngine and instead of UltimC its Ultim which looks a bit more cleaner but thanks once again for the help, im new to all these namespaces didnt use them in C++ either as there it was std:: etc :).

    #4299

    Richard Betson
    Participant

    im new to all these namespaces didnt use them in C++ either as there it was std:: etc 🙂

    I feel ya.. The last time I really used C/C++ was with Borland in the 90’s. For the last IDK 12-15 years I’ve just been using BRL products. But, once you get a hold of a few basic concepts Monkey 2 comes into focus pretty quickly.

Viewing 7 posts - 16 through 22 (of 22 total)

You must be logged in to reply to this topic.