abakobo

Forum Replies Created

Viewing 15 posts - 331 through 345 (of 455 total)
  • Author
    Posts
  • in reply to: Function variable pointer #7350

    abakobo
    Participant

    Mark has answered the issue and said function params are not actually passed by reference even if classes are reference based. (the problem of image pointers is something else):

    This is expected behaviour – functions parameters are not passed ‘by reference’ so when you assign to ‘img’ inside ‘MyImageLoading’ you are only assigning to a local variable which disappears when the function returns.

    I still don’t understand the exact behaviour of my above example though, and why it works..
    But this example shows a bit of reference based classes behavior in mx2:
    And if you use a global foo class for pointers you’ll end with the same kind of errors we have with image pointers.

    [/crayon]
    in reply to: Way to predefine/inline define an array of arrays? #7304

    abakobo
    Participant

    you can only predefine simple arrays so it will take two lines with your array of array example([][]). With a multidimensional([,]) array it’s not possible at all for now.

    this is the most you can have for now i think..

    [/crayon]
    in reply to: Way to predefine/inline define an array of arrays? #7299

    abakobo
    Participant

    you can have multidimensional arrays Myarr[x,x] or arrays of arrays Myarr[][] depending on what you need.
    multidimensional arrays are much simpler.
    you can directly initialize simple arrays only.

    simple and multidimentionnal arrays are explained in the latest docs (in github) but the arrays of arrays are not explained (see link)
    http://monkey2.monkey-x.com/forums/topic/syntax-for-array-of-arrays-jagged-array/

    an example of multidimentionnal array:

    [/crayon]
    in reply to: Temporary Standard Input – UPDATE #7298

    abakobo
    Participant

    do you recommend that I create a new array
    buffer = new int[1024] ?
    in C it will be

    [/crayon]

    but in monkey how would I reserve the memory without the use of the Cast operator?

    or should i use malloc!?

    in reply to: Temporary Standard Input – UPDATE #7295

    abakobo
    Participant

    Just tested you snippet but the update gave me a memory access violation..

    First example worked though.

    EDIT: had to modify a bit because the string was not ending correctly..

    [/crayon]
    in reply to: Canvas memory saturation (Bug?) #7281

    abakobo
    Participant

    Why do you create new canvas each render frame?

    I don’t, I just saw the bug(if it is) with some random simple test code.

    in reply to: Function variable pointer #7274

    abakobo
    Participant

    My example finished with a crash after a few time… Problem(?) with canvas that I reported.

    The Image objects are extending resource and resource are not GCed, and images can be created only after “New Appinstance”.
    The error message shows that it’s confused with some GCed object and some non GCed object. It converted the image to some GCed object but should not have done that.
    And your simple Function should just work. I tried with a method but it’s still the same problem!

    In my opinion you found 2 bugs! and I found one with my un-usefull example! Nice shot!

    EDIT:reported all 3 supposed bugs on github.

    in reply to: Function variable pointer #7266

    abakobo
    Participant

    Images are reference based so there is no need to use pointer… (or you re doing some specific external stuffs) It is supposed to passed by reference and any modifications should be kept.

    Did you Flushed the drawing commands: MyCanvas.Flush()? Note that flushing might slow down you process.

    It’s easier to help with the code..

    here is an example of a function drawing to an image with modification by reference.

    [/crayon]
    in reply to: Integrated docs gitHub community organisation #7162

    abakobo
    Participant

    OMG! I didn’t even thought about it! Will do so.

    in reply to: Continue Line #7156

    abakobo
    Participant

    Last info i saw on this:

    Lines can currently only be split after ‘[‘, ‘(‘ or ‘,’ tokens.

    in reply to: SOLVED: difference C vs C++ for importing simple function #7146

    abakobo
    Participant

    Solved:
    Adding this at the beginning of files

    [/crayon]

    and this at the end

    [/crayon]

    And I can now switch the .c and .cpp files.
    Looks like mx2 is cpp by default..

    in reply to: Error importing .h #7143

    abakobo
    Participant

    whenever a declaration create duplicates try to add static before it…

    in this case I added 3 static keywords and no errors now (on W7)

    this doesn’t mean it’s the good solution! but it avoids you spilltin to a .cpp src

    [/crayon]
    in reply to: Error importing .h #7141

    abakobo
    Participant

    try this without splitting (much easier and there’s something I didn’t get with the split with a .c file!)

    [/crayon]
    in reply to: Error importing .h #7139

    abakobo
    Participant

    Your problem here is that you give the implementation ({}) of your function in the .h file. It is ok to do that in c/c++ rules but it is considered BAD practice and nearly nobody does it. So I suppose Mark has not made mx2 compatible with it and sometimes (when using mojo for example) create duplicates of the same header for some internal mx2 reasons.

    What’s GOOD practise?
    -put static before your function if the implementation is in the .h file (ie: the{}). This will skip duplicates.

    [/crayon]

    Or
    -put your implementation in a .c/.cpp file Edit:could not make it work with a .c file!
    .h

    [/crayon]

    .cpp

    [/crayon]

    and import the .c/.cpp file along with the .h file in your .monkey2 file

    don’t forget to put the ; at end of lines. Sometimes it’s not mandatory but it’ll avoid you error messages.. (in the second case if you don’t put ; in the .h file it will fail to compile)

    for better practice use the #ifndef in your .h file

    [/crayon]

    but here of course test is a bit too simple for a def name!

    in reply to: Monkey2 #7138

    abakobo
    Participant

    the SDL_Event is a union in it’s SDL_events.h
    And SDL_Event is declared in extern section as a struct..
    Dunno if it will react exactly as a union but sdl2 events works!
    SDL_events.h

    [/crayon]

    sdl2.monkey2

    [/crayon]
Viewing 15 posts - 331 through 345 (of 455 total)