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.

Newcomers DBPro Corner / need help putting this into code

Author
Message
PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 9th Feb 2009 08:57
I am having trouble trying to come up with a way i can put this "thing" into actual code (or at least algorithm)

the "thing" i am refering to is:

i have a lets say a spinning cube that constantly returns value of its angle

what i need help with is every time the value of the angle changes by one, i need another parameter to change by the same amount (one)

so something like

if the angle of the cube went from 90 to 91 (spinning cube) i want another parameter to add 1 unit like X=X+1

i am having difficulty putting this into code

any help would be appreciated

thanks

dont hate people who rip you off,cheat and get away with it, learn from them
Dragon Knight
17
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 9th Feb 2009 09:14
Record Start Angle of cube

X=X+Object Angle OF CUBE minus StartAngOfCube

I think that's what you want?

PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 9th Feb 2009 09:23
i see what you are saying. The thing is DBP has a weird angle measurement system. instead of 0 to 360 its 0 to 180 them -180 to 0
thats how DBP defines my angles for some reason.

I think a simpler way to do this is:

if X added 1 to itself, then Y should also add 1 to itself

something like that

dont hate people who rip you off,cheat and get away with it, learn from them
Dragon Knight
17
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 9th Feb 2009 10:01
O.o i cannot say I've ever got it to go from 0 to 180 then down again heh.

It's probably how you rotate. Try actually increasing the angle itself by yourself instead of letting dbp do it heh, for some reason that seems to work fine for me .

I'm still not to sure exactly what you want the code to do? If you described more I'd probably be able to help more ^-^

PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 9th Feb 2009 10:14
well, your code did help me picture the code i need. i changed it a bit

X=X+Object Angle OF CUBE minus (objectAngOfCube+1)

i need the X value to go down one unit, every time the cube rotates 1 degree.

but for some reason, the x value is subtracting much faster than the cube rotates. It subtracted about 600 units from the X when the cube rotated 70 degreese

dont hate people who rip you off,cheat and get away with it, learn from them
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 9th Feb 2009 22:16
Try



PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 10th Feb 2009 13:51
Well, i think i am on the right track at least, i just need this to get to work the way i want it to work.

thanks guys

dont hate people who rip you off,cheat and get away with it, learn from them
Pharoseer
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: Right behind you
Posted: 11th Feb 2009 03:50
Oddly I've never noticed that behaviour. I always wrap my angle calculations with the wrapvalue() function though. It automatically constrains a value to the range [0..360]. That's probably the simplest way to go. In code it would look like:



Hope this helps,

Frank
PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 11th Feb 2009 05:12
Thanks Pharoseer, this will make my work easier

Now Ive been at this and i am kinda stuck



this is the closest representation of my code (with the same problem i am trying to figure out)

xs is the angle of the spinning object
and lcol is the variable

i need to have lcol subtract 1 from itself every time xs (the spinning cube) goes up by one degree

so its like a tradeoff, add one/ subtract one.

but for some reason it only subtracts once even if its in a loop (run the code you will see)

but if i add instead of subtracting like this

lcol=lcol+xs+(xs+1)

its gonna start adding both variables every time it changes (just what i want but in a different direction)

I tried all kinds of tricks and ways of going around it by adding more variables and stuff but it didnt work

help

thanks

dont hate people who rip you off,cheat and get away with it, learn from them
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 11th Feb 2009 06:03
Alright, well don't beat yourself up too much, but right in the middle of your loop, you have
. The value of lcol is reset every single cycle.

The first thing you want to do is to move that line above the loop. To solve the rest of the problem, however, you should think about variable types. The expression:
returns a float. However, when you use:
, xs is not a float and so anything after the decimal point is truncated. This in itself can alert you to when it changes by a whole degree, but because the angle wraps around 360, checking to see if the typecasted angle is different by one isn't going to work. Here's a way of getting around all of it:



Ask if you have questions.
PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 11th Feb 2009 06:28
DUDE! thanks, you just helped me so much!

i have a couple of questions so i understand your code better

i never got is oldx actually a function provided in DB or is it one of those you can rename as anything like (oldx=x) is same as (beef=xs)

also you seem to simply replace my xs variable with x, I see that you have oldx=x, you can use anything instead of x (cant you?) just seeing as i would like to name this variable as something less vague


and what does "dec" actually do? (i never used dec)

sorry if these are stupid

dont hate people who rip you off,cheat and get away with it, learn from them
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 11th Feb 2009 06:42
Glad it helped. And don't worry about stupid questions. If you're learning, there are no stupid questions.

oldx, x, and lcol are all variables. And so, all of the rules of variable naming logically apply to them. You can name them whatever you like.

And dec is a command that decrements (Hah, get it? ) the variable after it by one. You can optionally add another parameter to specify by how much you want to decrement the variable. Example:

PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 11th Feb 2009 07:22 Edited at: 11th Feb 2009 07:30
dude!, thats more than i barganed for, thanks man

Do you know how to get this code to work properly out of a function that is declared in the loop?

here is a code to clarify things





it subtracts only once

dont hate people who rip you off,cheat and get away with it, learn from them
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 11th Feb 2009 07:43
Well I hope you don't declare your function inside the loop.

Personally, I wouldn't use functions here. I don't think this is a practical enough situation. But if you were so possessed, it is most certainly possible. You'd have to declare your variables as global so your functions can use them. I also did a little rework and managed to eliminate the need for the variable oldx.

PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 11th Feb 2009 08:27
i like keeping all m code in functions because its easier to organize.

i have a problem with my own code where the globally declared lcol is just subtracting as fast as it can ignoring the x variable, but that's probably something in my code.

dont hate people who rip you off,cheat and get away with it, learn from them
PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 11th Feb 2009 08:58
just fixed it, Consolidated the spin() and fade() functions into one and it works fine!

you have been a big help today Kira, Thank you

dont hate people who rip you off,cheat and get away with it, learn from them
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 11th Feb 2009 16:59
Glad I could help.

Just a thought, you might want to look into subroutines as opposed to functions. It will allow you to break up and organize sections of the code like you're doing with your functions but it will also use the same variable scope as the rest of the program. That means no mucking around with globals. Just a thought.

PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 11th Feb 2009 21:13
ive been told that functions are much better than subroutines. Just keepeng the problem in one standard scope (functions) makes it less confusing

dont hate people who rip you off,cheat and get away with it, learn from them
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 11th Feb 2009 23:55
What? I strongly believe functions are no better than subroutines. Each has its own important role. Subroutines are very good for enclosing chunks of code that can be reused, while functions are useful for things that must return a value.
PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 12th Feb 2009 01:41
i thought subs could only return a value, while functions can do the same thing and other stuff making them better than subs. Well maybe in other languages its true.

but you say you dont have to deal with globals in subs right?

dont hate people who rip you off,cheat and get away with it, learn from them
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 12th Feb 2009 04:48
Hm? Subs cannot return a value. They really only exist for organization and structure. Functions however, should be designed to accomplish a specific task, like to find the result of some operation or something. The big problem with using functions in places where subroutines should be used is that any variables you want to use from outside of the function must be declared global, or you could pass a copy of it as a parameter. DBPro doesn't support passing arguments to functions by reference, so if the variable needs to be used elsewhere in the program, you have to make it global. I think this is probably why subroutines don't exist in languages that support passing by reference like C and C++. But in this one, subroutines and functions should be viewed as different things and therefore incomparable. Neither is better nor worse.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 14th Feb 2009 21:17
btw to fix the negative angles thing you could always try Wrapvalue(angle), which would translate the angle into something between 0 and 360. Not sure if that's relavent at this point though.

PAGAN_old
18
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 14th Feb 2009 22:21
yeah, i got that

dont hate people who rip you off,cheat and get away with it, learn from them

Login to post a reply

Server time is: 2024-11-25 10:50:17
Your offset time is: 2024-11-25 10:50:17