About managed structs and structs

Started by eri0o, Wed 12/07/2017 01:48:50

Previous topic - Next topic

eri0o

Hey,

The wiki needs an entry explaining managed structs and how to make array of them.

The wiki page is here: http://www.adventuregamestudio.co.uk/wiki/Referencing_custom_struct_types

The content I want to add is below, but I don't have clearance to be able to add content to the wiki:

Simple struct declaration

Code: ags

struct Pos {
 int x;
 int y;
}

Pos initialPosition;
Pos importantPosition[3];


This kind of struct though can't be passed as argument of a function.

Managed Struct

Code: ags

managed struct Pos {
 int x;
 int y;
}

Pos * initialPosition;
Pos * importantPosition;

//we can't use 'initialPosition = new Pos;' in the body, it needs to be in a function

function initialisePositions(){
    initialPosition = new Pos;
    importantPosition = new Pos[3];
    importantPosition[0] = new Pos;
    importantPosition[1] = new Pos;
    importantPosition[2] = new Pos;
    
}

function moveDancingTo(Pos * destination){

    // do something with destination

}



Managed strucs allow passing structs as parameters

AGA

Hey, sorry I didn't reply to your PM yet.  I'm having difficulty working out why you aren't able to log in to the wiki.  All forum users should be able to, so I'm not sure what's stopping you from doing it.  As soon as I work it out, I'll let you know!

eri0o

Hey AGA, I still can't post in the wiki.

SMF spam blocked by CleanTalk