swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swarm-Support] Sending parameters via message: m()


From: Rick Riolo
Subject: Re: [Swarm-Support] Sending parameters via message: m()
Date: Sat, 13 Dec 2003 08:08:35 -0500 (EST)

hi,

Re
> actually pass anything to getDistance.  I've seen reference to
> [modelSchedule ... message: M(getDistanceX:Y):20:30]; but I get errors
> with that syntax.

it would help to see the errors you get, but i'll hazard a guess
that you need to cast those parameters (and I'll assume you just
forget to type the : after the Y), eg what you want is

 [modelSchedule ... message: M(getDistanceX:Y:) : (id) 20 : (id) 30];

Note the syntax for createActionTo with a couple of parameters is
(from the swarm 2.1.1 ref manual):

- (id <ActionTo>)createActionTo: target message: (SEL)aSel : arg1 : arg2

The doc page perhaps should note those are supposed to be id arguments,
or things that can be safely cast as id arguments.
At any rate, note that the official name of a method with
parameters includes the colon's (and tags).  so in the M() you need it 
like this:
   message: M(getDistanceX:Y:)  : (id) 20 : (id) 30];
which is
              (SEL) aSel        :   arg   :   arg

--

re
> 2) How do I refer to the properties of an object?  I've tried
> aCustomer.xPos, where aCustomer is a Swarm Object called Customer with
> an internal variable called xPos, but get "request for member 'xPos' in
> something not a structure or union".

Its not clear to me what aCustomer is in your program.  
Ddid you do this:

   id aCustomer;       // or Customer *aCustomer;

   aCustomer = [Customer create...];

That aCustomer is a pointer to an object, not an object.

In any case, in general you can't or don't want to access 
instance variables (IV) that way.  If you are trying to access 
IVs of Customer from inside the Customer implementation file (Customer.m)
in regular instance methods, you can and should just refer directly to the
instance variables
-someCustomerMethod {
     ...
     aPos = 3;
If you are trying to access them from other classes/files, you should
define set/get accessor methods in the Customer class, and use those
   x = [aCustomer getAPos];
See examples of this in any of the Swarm demos (eg Heatbugs).

The only exception to this rule is in a class method, like +createBegin,
where you might need to refer to instances of the object that just got
created, eg, to initialize values.  Eg, a ObserverSwarm.m might have:

+createBegin: (id) aZone {
  ObserverSwarm *obj;
  id <ProbeMap>  probeMap;

  // Superclass createBegin to allocate ourselves.
  obj = [super createBegin: aZone];

  // Fill in the relevant parameters.
  obj->displayFrequency = 1;

where displayFrequency is an IV of ObserverSwarm.

you probably should read/scan through the Swarm Users Guide,
as i suspect it covers these topics.

- r


-- 
Rick Riolo                           address@hidden
Center for the Study of Complex Systems (CSCS)
4477 Randall Lab                
University of Michigan         Ann Arbor MI 48109-1120
Phone: 734 763 3323                  Fax: 734 763 9267
http://cscs.umich.edu/~rlr

On Sat, 13 Dec 2003, James Keirstead wrote:

> Date: Sat, 13 Dec 2003 12:33:00 -0000
> From: James Keirstead <address@hidden>
> Reply-To: address@hidden
> To: address@hidden
> Subject: [Swarm-Support] Sending parameters via message: m()
> 
> Hi,
> 
> I'm just beginning with SWARM and seem to be having trouble with some
> basic syntax issues.  I've searched the web but can't seem to find
> anything on the most basic question - such as:
> 
> 1) How do I send parameters via message: m()?
> 
> In buildActions of ModelSwarm.m I've got this code excerpt and I want to
> pass parameters for getDistance X and Y.
> 
>   modelSchedule = [Schedule createBegin: self];
>   [modelSchedule setRepeatInterval: 1];
>   modelSchedule = [modelSchedule createEnd];
>  [modelSchedule at: 0 createActionTo: aCustomer message:
> M(getDistanceX:Y:)];
> 
> This will compile and run, granted with garbage numbers since I don't
> actually pass anything to getDistance.  I've seen reference to
> [modelSchedule ... message: M(getDistanceX:Y):20:30]; but I get errors
> with that syntax.
> 
> 2) How do I refer to the properties of an object?  I've tried
> aCustomer.xPos, where aCustomer is a Swarm Object called Customer with
> an internal variable called xPos, but get "request for member 'xPos' in
> something not a structure or union".
> 
> Thanks for your help
> 
> Cheers,
> James Keirstead
> 
> _______________________________________________
> Support mailing list
> address@hidden
> http://www.swarm.org/mailman/listinfo/support
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]