Osterlaus
BSc Spammer
Beiträge: 1263
Registriert: 23. Aug 2007 12:46
Wohnort: DA

Hi there,
we don't really get how to use events. As far as we see, there are two events that might happen: the first is some tick-based event that is used to run the actions on a particle, the second is a handler for collisions.

Second question: what is meant by creating a new particle with "different behaviour"? We would implement a particle to do some random action on each tick, but we don't see how to get these two defintions together

Osterlaus
BSc Spammer
Beiträge: 1263
Registriert: 23. Aug 2007 12:46
Wohnort: DA

### Re: ex09 - Task 2

Next question, now about an event: if I add some handler to signal.change (not signal.changed!), the signature has to be (Val, Val). Does this allow us to not only react to a change, but also read old and new values?

Edit: okay, to clarify: I have a particle that is instantiated with a signal containing a position P: Point through

Code: Alles auswählen

class Particle(pos: Signal[Point], val myName: Char) {
val otherMove = pos.changed
otherMove += {_ => println("A change!")}
}

How can I change the value within pos such that the change fires? Whatever we try, it does not work...

salvaneschi
Mausschubser
Beiträge: 49
Registriert: 29. Mär 2013 23:51

### Re: ex09 - Task 2

Hi,

- we don't really get how to use events

The exercise is open on purpose. Be creative and try to use events. For example a particle can disappear...

- what is meant by creating a new particle with "different behaviour" ?

The easiest way is to create different types of particles that have different interaction/moving properties.

- Next question, now about an event

Not sure why you are using signals in the particles exercise. However this works for me:

println("Start")

class Particle(pos: Signal[Point], val myName: Char) {
val otherMove = pos.changed
otherMove += {_ => println("A change!")}
}

val v = Var(new Point(0,0))
def translate(p: Point, n: Int) = new Point(p.x + n,p.y + n)
val s = Signal{ translate( v(),10) }

new Particle(s, 'p')

v.setVal(new Point(1,1))

---- OUT -----
Start
A change!

Osterlaus
BSc Spammer
Beiträge: 1263
Registriert: 23. Aug 2007 12:46
Wohnort: DA

### Re: ex09 - Task 2

salvaneschi hat geschrieben:Not sure why you are using signals in the particles exercise.
Is there a better way, or an explanation about why not to use signals? Working with a undocumented closed-source library without much documentation or other hints might get confusing fast, and instead of giving a sharp distinction, you don't even define what a signal is, what an event is and why there are two different ways of solving it.... Sorry, I don't want to offend you, but this exercise task is so nebulous in terms of how to implement it that we got a bit confused about how to solve it the way you want us to...
salvaneschi hat geschrieben:However this works for me:

println("Start")

class Particle(pos: Signal[Point], val myName: Char) {
val otherMove = pos.changed
otherMove += {_ => println("A change!")}
}

val v = Var(new Point(0,0))
def translate(p: Point, n: Int) = new Point(p.x + n,p.y + n)
val s = Signal{ translate( v(),10) }

new Particle(s, 'p')

v.setVal(new Point(1,1))

---- OUT -----
Start
A change!
Thanks, the setval call was the missing point for us. Just working on inner values of the same point does change the values, but not fire the signal.

salvaneschi
Mausschubser
Beiträge: 49
Registriert: 29. Mär 2013 23:51

### Re: ex09 - Task 2

"Is there a better way, or an explanation about why not to use signals?"

Because the exercise is about events...

"Working with a undocumented closed-source library without much documentation or other hints might get confusing fast"

Did you look into the test cases ? For example:

var test = 0
val e1 = new ImperativeEvent[Int]()
e1 += ( (x: Int) => { test += x })
e1(10)
assert(test == 10)

is almost all you need to know to solve the exercise...

"and instead of giving a sharp distinction, you don't even define what a signal is, what an event is "

Did you attend the last exercise ?

Computer
Erstie
Beiträge: 18
Registriert: 16. Apr 2013 12:24

### Re: ex09 - Task 2

@tutors
Are there no slides in ex09 like every week wednesday?
Did you forget to commit the exercise-slides?

olg
Sonntagsinformatiker
Beiträge: 297
Registriert: 1. Okt 2008 19:24

### Re: ex09 - Task 2

Computer hat geschrieben:@tutors
Are there no slides in ex09 like every week wednesday?
Did you forget to commit the exercise-slides?
There is an intro to reactive programming in the SVN 'slides' directory.
"To Perl, or not to Perl, that is the kvetching." ~Larry Wall

0pa
Mausschubser
Beiträge: 44
Registriert: 20. Sep 2011 16:33

### Re: ex09 - Task 2

I think Osterlaus is right.

The Scala exercises are formulated way too short. For Task 2 it's basically 5 sentences.
Most of us have pretty much no idea what to implement, how to implement and what this exercise is for.

The Java exercises were all about those design patterns; which I really liked. It was kind of fun to do them and I saw why they are usefull and sensfull.
However this Scala thing is a big mystery to me. I don't see what it should teach us. For me, it's just timewaste.

Another point is the Scala IDE. Setting up a new enviroment is for many ppl no trivial thing. When you have already an eclipse enviroment with a lot of plugins running, the Scala IDE is pia.
(I have to restart eclipse 5-10 times until it finally starts)

svenamann
BASIC-Programmierer
Beiträge: 145
Registriert: 6. Mai 2013 18:04

### Re: ex09 - Task 2

0pa hat geschrieben:The Scala exercises are formulated way too short. For Task 2 it's basically 5 sentences.
Most of us have pretty much no idea what to implement, how to implement and what this exercise is for.
The piont is for you to play around with an advanced language feature, in a scenario that leaves you as much room as possible, but that we can still somehow judge to give you points.
0pa hat geschrieben:The Java exercises were all about those design patterns; which I really liked. It was kind of fun to do them and I saw why they are usefull and sensfull.
However this Scala thing is a big mystery to me. I don't see what it should teach us. For me, it's just timewaste.
Have you attended the lecture and exercises? As far as I remember we talked about how advanced language features have an impact on software design. Since you don't know the features, we give you a chance to get to know them. From the "fun" part of the lecture you should have enough experience to judge what you gain from the features in terms of design possibilities.
0pa hat geschrieben:Another point is the Scala IDE. Setting up a new enviroment is for many ppl no trivial thing. When you have already an eclipse enviroment with a lot of plugins running, the Scala IDE is pia.
(I have to restart eclipse 5-10 times until it finally starts)
How about setting up a second eclipse installation without "a lot of plugins running"?