Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Faulty Operations on arrays

Author
Message
Kjelle
16
Years of Service
User Offline
Joined: 29th Sep 2002
Location:
Posted: 6th Oct 2002 18:02
Following operation returns nonsense values
trying to negate a velocity vector:
ball#(t,vely)=-1*ball#(t,vely)

Same operation works while using dummys:

temp#=ball#(t,vely)
temp#=-1*temp#
ball#(t,vely)=temp#


why ?
ZeldaPhreak
16
Years of Service
User Offline
Joined: 9th Sep 2002
Location:
Posted: 6th Oct 2002 18:47
try putting 'ball#(t,vely)' in parentheses so the proper l-value is returned:
ball#(t,vely) = -1 * ((ball#(T,vely))

Kjelle
16
Years of Service
User Offline
Joined: 29th Sep 2002
Location:
Posted: 6th Oct 2002 20:56
I changed the array to a one dimensional array but it did not work either:

vely#(t)=-1*((vely#(t)))
ZeldaPhreak
16
Years of Service
User Offline
Joined: 9th Sep 2002
Location:
Posted: 6th Oct 2002 23:52
Make sure you use the spaces.

ZeldaPhreak
16
Years of Service
User Offline
Joined: 9th Sep 2002
Location:
Posted: 6th Oct 2002 23:56
between 1, the '*', and the '(' that is; or if that doesn't work, then I believe I read on some 'other' forum, (well at least it WAS a forum lol), that you would have to put extra spaces between the end parentheseses too, if not all of them.

Ratty Rat
16
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 7th Oct 2002 20:08
The problem is probably that DB is treating the -1 as an integer, and then getting everything else wrong in the conversion.
You need to make sure DB knows the -1 is a floating point number thus:-

ball#(t,vely)=-1.0*ball#(t,vely)

Certainly this seems to fix it on my system, not sure why using a non-arrayed variable works. When using DB I always make sure I put n.0 when working with floats, this is always good practice with any language as otherwise the compiler/interpreter may convert your floats to ints in the fucntion.

Login to post a reply

Server time is: 2019-05-24 16:17:08
Your offset time is: 2019-05-24 16:17:08