First time here? Check out the FAQ!
x

ifTrue or varIfTrue?

0 votes
813 views
hello hello,

for my performance of KISS2018 I am using a script in which the predator sounds the prey sound when they are in the same position (of the quadriphonic listening space).

 

in one script I try this, but if I put "ifTrue" I am asked to use "varIfTrue", if I use "varIfTrue", the interpreter tells me I cannot use varIfTrue with HotValues. Iso, how is the right way to get this?

 

here the code:
asked Jul 18, 2018 in Capytalk & Smalltalk by domenico-cipriani (Master) (3,110 points)
| preyposition predatorposition hunt |
preyposition := 1 to: 4 collect: [:i | ('prey' & i) asHotValue].
predatorposition := 1 to: 4 collect: [:i | ('predator' & i) asHotValue].
hunt := #(0 0 0 0).
1 to: 4 do: [:j |
    1 to: 4 do: [:i |
    ((preyposition at: i) = (predatorposition at: j)) ifTrue: [hunt at: i put: 1]]].

 
1 to: 4 do: [:j |
    hunt start: 0 s
    die: ('die' & i) asHotValue
    hunt: (hunt at: i)
]

p.s. when dead become 1 the corresponding sound disappear.

2 Answers

0 votes
 
Best answer

Here's an approach using Replicator and TransformEventValues.

The Replicator creates a Sound for each prey. That Sound generates a gate any time that prey occupies the same position as any predator. The equals test has a tolerance control so they can be near each other and not have to be on top of each other.

 

answered Jul 18, 2018 by ssc (Savant) (128,080 points)
selected Jul 18, 2018 by domenico-cipriani
wow SSC that's fantastic, I didnt think to use a "TransformEventValues",
I am really happy now :)
a last question, what does it means "die - 0" in
{ | die |
die := 0.
(1 to: 4) do: [ :i | die := die + (((!Predator suffix2: i) - !Prey) abs lt: !Tolerance)].
die - 0}

?
Oops! You can just drop the minus zero. It doesn't do anything at all (it was accidentally left in there after an experiment). Send your predators in to devour it! Last line should just be:
die}
Hello SSC, I have noticed that this TransformEventValue + Replicator, dramatically increases DSP usage (around 15 %). is there any solution less expensive computationally?
0 votes

Hi Domenico,

It looks as if you may have intended some of the tests and updates specified in the Script to take place during run time (while the Sound is playing) rather than at compile time (which is when all the Smalltalk code will be evaluated, before the Sound starts). So the first step is to tease apart which actions should take place in real time and which could take place before the Sound starts. It looks to me like the following actions are intended to take place while the Sound is running:

1 to: 4 do: [:j | 
    1 to: 4 do: [:i |
    ((preyposition at: i) = (predatorposition at: j)) ifTrue: [hunt at: i put: 1]]].


and

1 to: 4 do: [:j |
    hunt start: 0 s 
    die: ('die' & i) asHotValue
    hunt: (hunt at: i)
]

Is that correct? 

answered Jul 18, 2018 by ssc (Savant) (128,080 points)
yes, correct. these two actions take place when the sound is running.
how can I fix my script?
When a predator and prey occupy the same position, does the prey always die?
Will it be 4 predator and 4 prey? (the number of comparison tests grows with the square of the number of entities).
How do you update the the predator and prey locations?
One more question, is it one-dimensional (as in your Script)? Where each entity has an x position? (not x, y)
so, I just put one dimension in the question  for economy.
actually I have a x and an y position. and the predator can eat the prey only if it is "old" enough and if its trigger happen at the same time of the prey's trigger.
actually I expanded  ypur example with all my variables and it is working!
by the way prey always die if all these conditions are true. and of course they only die once.
my ecosystem is slowly growing for the KISS ;)
...