swarm-hackers
[Top][All Lists]
Advanced

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

[swarm-hackers] Re: Swarm, Heatbugs, and forEach loops...


From: Nima Talebi
Subject: [swarm-hackers] Re: Swarm, Heatbugs, and forEach loops...
Date: Wed, 11 Nov 2009 00:44:53 +1100

Nevermind, I figured it out.

I've updated my clone of Heatbugs (git tree), which now allows user to interact with the state of the Heatbug agents, changing their idealTemp and outputHeat minimums and maximums.

I did that like so...

- (void)reconfigureHeatbugs {
    [heatbugList forEach:M(setRandomIdealTemperatureInRange:to:) :minIdealTemp :maxIdealTemp];
    [heatbugList forEach:M(setRandomOutputHeatInRange:to:) :minOutputHeat :maxOutputHeat];
}

...and each time the user moves the sliders, MyDocument calls this method...

- (IBAction)setMaxOutputHeat:(id)sender {
    ...
        int tA = min([sender intValue], (int)[sender maxValue] - 100);
        [swarm setMaxOutputHeat:NSInt(tA)];
        
        int tB = min(tA, [[swarm minOutputHeat] intValue]);
        [swarm setMinOutputHeat:NSInt(tB)];
        [minOutputHeat setIntValue:tB];
        [minOutputHeat setNeedsDisplay];
        
        [swarm reconfigureHeatbugs];
   ....
}


...does anyone see anything wrong with that?  I ask because I still feel a little daunted by the amount of code in this framework, so I'm never quite certain that I'm going about things the right way.

Nima

On Tue, Nov 10, 2009 at 9:52 PM, Nima Talebi <address@hidden> wrote:
Hi, I'm a little confused (as I usually am looking at Swarm) on how iteration is supposed to work...

I have added some sliders and input widgets to my own branch of heatbugs, and so each time the user acts on these input widgets, I need to update the state variables stored in each Heatbug object.

For example, I would like to have something like this...

- (void)reconfigureHeatbug:(Heatbug *)hbug;


- (void)reconfigureHeatbugs {

    int i;

    Heatbug *hbug;

    for(i=0; i<numBugs; i++) {

        hbug = [heatbugList objectAtIndex:i];

        [self reconfigureHeatbug:hbug];

    }

}    


Of course that's not possible, as the heatbugList is not an NSArray, it is an id conforming to the <List> protocol.  Looking at surrounding code, I think maybe I'm supposed to do something along the lines of...

- (void)reconfigureHeatbugs {

    id fEAction = [modelActions createActionForEach:heatbugList

                                            message:M(reconfigureHeatbug:)];

}


..but that's obviously wrong since I have no idea what I'm doing - and what is M?

As a side-question - What would make life easier is being able to highlight a function/method/class/whatever in Xcode - say M - then right-click and select 'Jump to definition' - Anyone know how I can get that working?

Nima



--
Nima Talebi
web: http://ai.autonomy.net.au/People/Nima
gpg: B51D 1F18 D8E2 B702 B027 23A4 E06B DAC1 BE70 ADC0

reply via email to

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