Export variable from init to global ?

22 views
Skip to first unread message

Patrick Giraudoux

unread,
Aug 6, 2014, 9:05:52 AM8/6/14
to
Hi,

Following https://groups.google.com/forum/#!topic/gama-platform/vEKH0wIFFWA, in the init section I have created a list of cells as following:

create zoneFav from:zonefavorable;
zoneFav la_zone_fav <- one_of(zoneFav);
list<cellPred> mySel<-cellPred overlapping(la_zone_fav);

I would like to use mySel elsewhere in species behaviour. For instance, I want to define the cell destination of each agent of the species pred in av reflex 'move1' as following:

list<cellPred> dest1<-my_cellPred neighbours_at predMov where((each.nb_ater>my_cellPred.nb_ater) and empty(each.agents)); // list of cells with 'expected conditions'
list<cellPred> dest2<-mySel inter dest1; //intersection between the list of cells overllaping zoneFav and the list of cells meeting the expected conditions
cellPred dest <- one_of(dest2); // selection of one of those cells

However, mySel although declared in init (hence global)  looks like not being accessible from a reflex inside a species:"The variable mySel is not defined or accessible in this context. Check its name or declare it". In other words is there a way to export mySel to global from the init section or another way to make it global?

Any hint appreciated,

Thanks in advance,

Patrick

Srirama Bhamidipati

unread,
Aug 6, 2014, 9:58:18 AM8/6/14
to gama-p...@googlegroups.com
Hi 

I am working on something of a similar problem. :( , you ask the question at the right time :) I shall wait for GAMA team's response. Meanwhile.....

From the help manual I gather, that init values are valid only to start the simulation whether it is init in global, or init in species. Currently to make them accessible, I assign init variables to a species variable or a global variable before I leave the init { } . So far it is working for me. ( I think so ) Hope it helps you.

regards,
Srirama

Alexis Drogoul

unread,
Aug 6, 2014, 10:02:10 AM8/6/14
to gama-p...@googlegroups.com
Hi,

If you need to reuse mySel somewhere else in a species (or in your model), the best is to declare it as an attribute of global. Something like:

global {

list<cellPred> mySel;


init {

mySel<-cellPred overlapping(la_zone_fav);

}
….
}

Cheers
Alexis


Le 6 août 2014 à 15:05, Patrick Giraudoux <patrick....@univ-fcomte.fr> a écrit :

> Hi,
>
> Following https://groups.google.com/forum/#!topic/gama-platform/vEKH0wIFFWA, in the init section I have created a list of cells as following:
>
> create zoneFav from:zonefavorable;
> zoneFav la_zone_fav <- one_of(zoneFav);
> list<cellPred> mySel<-cellPred overlapping(la_zone_fav);
>
> I would like to use mySel elsewhere in species behaviour. For instance, I want to define the cell destination of each agent of the species pred in av reflex 'move1' as following:
>
> list<cellPred> dest1<-my_cellPred neighbours_at predMov where((each.nb_ater>my_cellPred.nb_ater) and empty(each.agents)); // list of cells with 'expected conditions'
> list<cellPred> dest2<-mySel inter dest1; //intersection between the list of cells overllaping zoneFav and the list of cells meeting the expected conditions
> cellPred dest <- one_of(dest2); // selection of one of those cells
>
> However, mySel although declared in init (hence global) looks like not being accessible from a reflex inside a species:"The variable mySel is not defined or accessible in this context. Check its name or declare it"
>
> Any hint?
>
> Thanks in advance,
>
> Patrick
>
>
> --
> You received this message because you are subscribed to the Google Groups "GAMA" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
> To post to this group, send email to gama-p...@googlegroups.com.
> Visit this group at http://groups.google.com/group/gama-platform.
> For more options, visit https://groups.google.com/d/optout.

--
Senior Researcher, UMI UMMISCO 209, IRD & UPMC, France.
Invited Researcher, DREAM, Can Tho University, Viet Nam.
--
alexis....@gmail.com | http://tiny.cc/liqemw
[Vietnam] +84915088155 [France] +33608698845
--
GAMA: https://code.google.com/p/gama-platform/

HUYNH Nghi

unread,
Aug 6, 2014, 10:03:09 AM8/6/14
to gama-p...@googlegroups.com
Hi,
As my opinion, you are using a <<let>> which declare a temporary variable in a block of statement ( in this case : block init), it;s not a permanent attribute of a species ( user-defined species, world). So it can access only in where it declare, because it will be destroy after execution of this block.
Cheers.

--

Patrick Giraudoux

unread,
Aug 6, 2014, 10:31:02 AM8/6/14
to gama-p...@googlegroups.com
Many thanks everybody for your suggestions.

A posteriori, Alexis' solution should have been obvious to me (ashes on my head ! This is basic programming - even for an humble ecologist newbie). Declare it in global, update it anywhere else (or so...).

Cheers,

Patrick


Reply all
Reply to author
Forward
0 new messages