How to get location from previous agent?

29 views
Skip to first unread message

José Fernandes

unread,
Jan 30, 2015, 10:54:56 AM1/30/15
to gama-p...@googlegroups.com
Hello!

I'm got stuck in what must be something very simple.

How can I get the location from the previous agent in this code? I need to place the first agent randomly but after that all agents must be in line (sequence) with the first agent position.

Thanks!

Enter code here...species codon {
        string nucleotide_type;
        string aminoacid;
        const color type: rgb <- 'black' as rgb;
        const size type: float <- float(min_size_of_agents*2);
        geometry shape <- sphere (size) simplification (1);
        init {
             nucleotide_type <- first(nucleotides_list);
             remove first(nucleotides_list) from: nucleotides_list;
             
             aminoacid <- first(aminoacids_list);
             remove first(aminoacids_list) from: aminoacids_list;
             
             if int(self) = 0{
                 self.location <- {rnd(world_x), rnd(world_y), rnd(world_z)};
             }
             
             //HELP
             //self.location <- get location from previous agent?;
          }
        aspect default {
            draw shape color: color;
        }
}



Patrick Taillandier

unread,
Jan 30, 2015, 11:04:13 AM1/30/15
to gama-p...@googlegroups.com
Hi,

In this case is to use the block of the create statement rather than the init block to set the location:

point prev_loc <- any_location_in(world);
create codon {
       if int(self) = 0{
          location <- prev_loc;
     } else {
           location <- prev_loc + {20, 0};
     }
     prev_loc <- location
}

Cheers,

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.

José Fernandes

unread,
Jan 30, 2015, 11:21:32 AM1/30/15
to gama-p...@googlegroups.com
Hi Patrick.

Thank you so much!

Jose
Reply all
Reply to author
Forward
0 new messages