[go-nuts] Re: Is it possible to simplify this snippet?

2019-05-02 Thread Sundararajan Seshadri
For your question, the answer is NO. Your version is the most simple one. If it is relating to making it meaningful or more documented, you can try something like: //checkDirection returns the direction for the key pressed: 'up', 'down', 'left', 'right'. Any other return variable (nil) will not

Re: [go-nuts] Re: Is it possible to simplify this snippet?

2019-05-01 Thread Tyler Compton
On Wed, May 1, 2019 at 7:28 PM wrote: > if rl.IsKeyDown(rl.KeyA) { p.Rect.X-- } > if rl.IsKeyDown(rl.KeyD) { p.Rect.X++ } > if rl.IsKeyDown(rl.KeyW) { p.Rect.Y-- } > if rl.IsKeyDown(rl.KeyS) { p.Rect.Y++ } > It's worth mentioning though that this will not survive a gofmt. In general, I've found

[go-nuts] Re: Is it possible to simplify this snippet?

2019-05-01 Thread marcusljx
if rl.IsKeyDown(rl.KeyA) { p.Rect.X-- } if rl.IsKeyDown(rl.KeyD) { p.Rect.X++ } if rl.IsKeyDown(rl.KeyW) { p.Rect.Y-- } if rl.IsKeyDown(rl.KeyS) { p.Rect.Y++ } On Wednesday, May 1, 2019 at 8:38:10 PM UTC+8, гусь wrote: > > if rl.IsKeyDown(rl.KeyA) { > p.Rect.X -= 1 > } > if rl.IsKeyDown(rl.KeyD)

[go-nuts] Re: Is it possible to simplify this snippet?

2019-05-01 Thread mrpoundsign
I misread the ternary expression. I saw 1:0 as 1.0. Stupid getting old. On Wednesday, May 1, 2019 at 5:47:44 PM UTC-7, mrpou...@gmail.com wrote: > > > > On Wednesday, May 1, 2019 at 1:32:01 PM UTC-7, lgo...@gmail.com wrote: >> >> Great example of why future Go updates should include the ternary >

[go-nuts] Re: Is it possible to simplify this snippet?

2019-05-01 Thread mrpoundsign
On Wednesday, May 1, 2019 at 1:32:01 PM UTC-7, lgo...@gmail.com wrote: > > Great example of why future Go updates should include the ternary operator. > Your code is mess-ey when written using keywords 'if' or 'switch' > but using '?' it becomes much cleaner > > p.Rect.X += rl.IsKeyDown(rl.KeyA

Re: [go-nuts] Re: Is it possible to simplify this snippet?

2019-05-01 Thread Steven Wiley
Two slightly different version for what is is worth (not much): checkKey:=func(k int) int { if rl.IsKeyDown(k) { return 1 } return 0 } p.Rect.X+=-checkKey(rl.KeyA)+checkKey(rl.KeyD) p.Rect.Y+=-checkKey(rl.KeyW)+checkKey(,rl.KeyS) or checkKey:=func(m,p int) (i int) { if rl.IsKeyDown(

Re: [go-nuts] Re: Is it possible to simplify this snippet?

2019-05-01 Thread Burak Serdar
On Wed, May 1, 2019 at 2:31 PM wrote: > > Great example of why future Go updates should include the ternary operator. > Your code is mess-ey when written using keywords 'if' or 'switch' > but using '?' it becomes much cleaner > > p.Rect.X += rl.IsKeyDown(rl.KeyA) ? -1:0 + (rl.IsKeyDown(rl.Key

[go-nuts] Re: Is it possible to simplify this snippet?

2019-05-01 Thread lgodio2
Great example of why future Go updates should include the ternary operator. Your code is mess-ey when written using keywords 'if' or 'switch' but using '?' it becomes much cleaner p.Rect.X += rl.IsKeyDown(rl.KeyA) ? -1:0 + (rl.IsKeyDown(rl.KeyD) ? 1 : 0 ) p.Rect.Y += rl.IsKeyDown(rl.KeyW)