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 / A variable won't change values?

Author
Message
Deet
16
Years of Service
User Offline
Joined: 15th Mar 2010
Location:
Posted: 26th Feb 2012 19:45 Edited at: 26th Feb 2012 20:31
I'm building a racing game, and I'm running into trouble getting my clock element to display correctly. I want to have the clock displayed as a 3d object on a scoreboard, and it does just that. However, while the element displays the correct time, it does not display the correct width of the digits.

Here is the code for the section in question. Everything works except the width determination for the object.


And here is the width determination dissected. The WH() array is a float value.

This gets the width and height of image that will be the texture on the plane.
WH(0,P)=image width(digit(0,StatVal(0,P)))
WH(1,P)=image height(digit(0,StatVal(0,P)))

This builds the plane. TDH# is the height of the element. When I do this math on pen and paper, it produces accurate size results. It uses the formula ObjectWidth/ObjectHeight=ImageWidth/ImageHeight and solves for Object Width.
StatOb(0,P)=nobplane(TDH#*WH(0,P)/WH(1,P),TDH#)

Despite the number images having different widths and heights (the widths range from 22 for the 1 to 40 for the 0, the heights are 49-51), the width for every object is exactly the same. I've bugtested the code, and every value is correct except for the calculated width, which is always constant.

I cannot figure out why it's constant. The old objects are deleted, and new objects are created with a width of TDH#*WH(0,P)/WH(1,P). WH(0,P) and WH(1,P) are filled with the correct image size values. TDH# = 2.382. When I solve the equations on paper, I get an object width value that varies based on the dimensions of the image. But the program always returns the same value for each object, despite having different images.

edit: edited code for clarity, added more remtags. These forums could use a preview post button...
Deet
16
Years of Service
User Offline
Joined: 15th Mar 2010
Location:
Posted: 26th Feb 2012 21:00 Edited at: 27th Feb 2012 18:25
I solved it. The problem was the nobplane function. I had x and y declared in the function as integers and I was passing reals and floats into it.


How often do you find that mistakes and bugs in your code are caused by something as simple as forgetting to place a symbol correctly?

Login to post a reply

Server time is: 2026-07-09 22:48:44
Your offset time is: 2026-07-09 22:48:44