Run SARL Agent from a Java Program with params

22 views
Skip to first unread message

Ayoub Charef

unread,
Mar 16, 2019, 6:53:42 AM3/16/19
to sarl
Hello ,

I am trying to   use the bootstrap for launching an agent  from a Java Program and i need to send some parametres  to my agent ,but i don't know how to get it .

this is my code 

public class Main {


public static void main(String[] args)

{

SREBootstrap bootstrap = SRE.getBootstrap();

    try {

    bootstrap.startAgent(Interface.class);

       /* start an agent with parametres sned value="Up" */

    bootstrap.startAgent(CarAgent.class,"Up");

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


}


}


agent CarAgent 

{

uses CarCapacity, Schedules

//______ my position ____

on Initialize 

{

// how can i get this params ="Up"

setSkill(new CarsSkills)


createbody(posX, posY, "Up")

every(50)

[

posY =posY+2

move(posX, posY, "Up")

]

}


on Destroy 

{


}


}

Stéphane Galland

unread,
Mar 16, 2019, 8:43:17 AM3/16/19
to sa...@googlegroups.com
Dear Ayoub.
Within the "Initialize" event handler, you could have access to the instance of the event with the "occurrence" keyword.
The "Initialize" event contains a field, named "parameters" that contains all the parameters provided when creating the agent.
The list of parameters in the event is of type "List<Object>". It means that you will have certainly to cast the value.

The result code of your agent becomes:

agent CarAgent {

   uses CarCapacity, Schedules

   //______ my position ____

   on Initialize {

        // how can i get this params ="Up"


       
val param = occurrence.parameters.get(0) as String

        setSkill(new CarsSkills)


        createbody(posX, posY, param)

       every(50) [
            posY =posY+2

           move(posX, posY, param)

       ]

   }


    on Destroy {

   }


}



Ayoub Charef

unread,
Mar 16, 2019, 9:51:14 AM3/16/19
to sarl
Thank you  . 
Reply all
Reply to author
Forward
0 new messages