The Daily Click ::. Forums ::. Klik Coding Help ::. Angle Problem
 

Post Reply  Post Oekaki 
 

Posted By Message

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
25th February, 2006 at 18:10:39 -

Ok, I'd really appreciate some help with this.

I want to use a counter to store a number. This number should increase/decrease when you press up/down.
I also want another counter, with the above number shown as an angle - ie. When the number exceeds 359, it should "wrap" around to 0 again. This much I can do, using the mod function in mmf.

However, I also want the number in the second counter to stay positive when it goes below 0. For example, -90 should become 270. Is there a formula for calculating this? (in a single line, and without extensions).

Like I said, any help would be much appreciated

 
n/a

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
25th February, 2006 at 18:16:29 -

http://www2.create-games.com/article.asp?id=1221

http://www2.create-games.com/article.asp?id=1588

 
Craps, I'm an old man!

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
25th February, 2006 at 18:29:09 -

thanks, but those don't actually answer my question. the problem i have is just with keeping the angle between 0 and 359. i think i've seen it done before, but after searching here and at the clickteam forum i haven't found a solution.

 
n/a

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
25th February, 2006 at 18:31:15 -

uh how about

Counter is < 0 - Add 360 to counter.

 
Craps, I'm an old man!

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
25th February, 2006 at 18:39:13 -

Genius! That's given me an idea;

* always (or whatever)
set "Counter2" to (( value( "Counter" ) mod 360 ) + 360 ) mod 360

that works!

thankyou

 
n/a

DanielRehn



Registered
  18/09/2002
Points
  139
25th February, 2006 at 19:23:45 -

why
* always (or whatever)
set "Counter2" to (( value( "Counter" ) mod 360 ) + 360 ) mod 360

when u can do this
* always (or whatever)
set "Counter2" to ( value( "Counter" ) + 360 ) mod 360

less code!

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
26th February, 2006 at 00:26:57 -

Thanks for the suggestion, but that wouldn't work if counter1 went below -360 (if you turned more than one full turn anticlockwise, which is quite likely after a while). You'd start to get negative answers again; -400 for example, would produce the answer -40.

The first mod puts the number in the range of -360 to 360; adding the 360 then shifts the value into the range 0-720 (so no negative values); the second mod then puts the number in the range 0-360, which was the aim of the exercise

Image Edited by the Author.

 
n/a

CUBE



Registered
  04/12/2004
Points
  283
26th February, 2006 at 04:34:55 -

Wouldn't it be easier to do

-Counter < 0
Add 360 to Counter

-Counter > 359
Subtract 360 from Counter

That keeps the range within 0-360 and it using less calculation than all that mod stuff.

 
n/a

DanielRehn



Registered
  18/09/2002
Points
  139
26th February, 2006 at 12:15:40 -

Sorry...did'nt se that you were using two counters... If you only use 1 this will work... since the moment it goes below 0 (eg -1) it will add 360 (359 then)...

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
26th February, 2006 at 20:49:30 -

CUBE: That's 2 separate events, so you couldn't use it as part of a more complicated formula. I may or may not use two counters (that was just me trying to explain the problem as clearly as I could), but I always prefer to do stuff in the minimum number of events anyway - it's more "elegant", and in theory, it'll make your game run quicker too.

Image Edited by the Author.

 
n/a

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
26th February, 2006 at 21:08:57 -

Umm, yeah you could use it as part of a bigger formula, just follow order of events and you'll be fine, cause every event below those 2 events would have the counter between 0-360.

But then again, I'm not entirely sure of what you are trying to do, so I guess it wouldn't work under some conditions.

 
Craps, I'm an old man!
   

Post Reply



 



Advertisement

Worth A Click