coding problem

zed

Legend
EDIT: OK my bad, board_heights[ num ];
so I solved it, doh!

Sorry for the thread, but my mind cant think, this is one of those problems Ive had over the last 30 years, where it doesnt make sense, usually its cause Ive done something wrong
Code:
for ( int x=0; x<VERT_HEIGHT_RESX; x++ ) {
           for ( int y=0; y<VERT_HEIGHT_RESY; y++ ) {
               board_heights[x+VERT_HEIGHT_RESX*y] = 0.0f;

               int num = dungeon.tiles[x+VERT_HEIGHT_RESX*y];
               if ( num >= 'a' && num <= 'z' ) {
                   board_heights[x+VERT_HEIGHT_RESX*y] = dungeon.ReturnFloatFromKeyValue( num );
                   print( board_heights[x+VERT_HEIGHT_RESX*y] );[B] [COLOR=#ff4d4d]// good values[/COLOR][/B]
                   height_field[ x+VERT_HEIGHT_RESX*y ] = board_heights[x+VERT_HEIGHT_RESX*y];[B] [COLOR=#ff4d4d]// works[/COLOR][/B]
               }
           }
       }


       for ( int x=0; x<VERT_HEIGHT_RESX; x++ ) {
           for ( int y=0; y<VERT_HEIGHT_RESY; y++ ) {
               int xx = x;//(x<VERT_HEIGHT_RESX) ? x : VERT_HEIGHT_RESX-1;
               int yy = y;//(y<VERT_HEIGHT_RESY) ? y : VERT_HEIGHT_RESY-1;
               float height = 0.0f;
               int num = dungeon.tiles[ xx+VERT_HEIGHT_RESX*yy ];
               if ( num >= 'a' && num <= 'z' ) {
                   height = board_heights[ num ];
                   print( height + " " + num ); [B][COLOR=#ff4d4d] // always 0.0[[/COLOR]/B]
               }
           }
       }

why is height always 0.0?
ta zed

edit ok you cant do color or bold in a code field
 
Last edited:
no time for comments , though seriously I do occasionally place comments in, though more along the lines of WTF, etc
 
put a breakpoint just before put a watch on the variable you want and step through

why is height always 0.0?
because you don't have a variable called height
edit:
yes you do and you've assigned it a value of 0.05859375
 
Last edited:
for ( int y=0; y<VERT_HEIGHT_RESY; y++ )
shouldnt that be a while loop or a repeat until
eg:
y=0 *initialise variable
while y<VERT_HEIGHT_RESY
begin;
do stuff
increment y
end;
 
Syntactically, While / Repeat loops are worse looking than foreach / for loops, especially when you don't need the loop counter to exist when the loop is finished.

Just my own quirkiness style.
 
if ( num >= 'a' && num <= 'z' )
I dont know the language so i dont understand this line
num is an integer - yes ?
but your trying to assign it a value of "a" which is a char I see no place where a variable called a is declared
ps:
is && logical and ?
 
put a breakpoint just before put a watch on the variable you want and step through
I’m using unity, I never actually took the time out to figure out how to do stepping through the code with it, eg with breakpoints etc hehe
I should take the time and learn

I prefer for loops also , or foreach better (though slower)

Davros, I’m just comparing two numbers, sure I chould cast the char to an int, but hey (or is it a char?) cause it doesn’t complain so perhaps the compiler converts ‘a’ to 65int during compilation

FWIW this is what I’m coding
 
Typically in C based languages, chars are shorts and autocast to ints.
That loop is two expressions joined by the logical AND ( && ) operator.
Its roughly: if the character is inclusive between lowercase A and lowercase Z.
 
But you should use for loops to loop a certain number of times eg: for i = 1 to 10 or for i = 1 to x
you shouldnt use for loops as a loop while condition is true or a loop until condition = false

ps: 0.0f is hex yes
here :
https://www.rapidtables.com/convert/number/hex-to-decimal.html
gives 0.05859375 in decimal

here :
https://www.binaryhexconverter.com/hex-to-decimal-converter
gives invalid hexadecimal value

here :
https://codebeautify.org/hex-decimal-converter
gives 0

pps:
board_heights[x+VERT_HEIGHT_RESX*y]
is that an array of board_heights ?
 
There are conditions in programming where your loop is based on an abstract condition becoming true, rather than simply looping for X times. A while until true is perfectly fine for certain circumstances.
 
Yes I sometimes use while loops then, though less frequently then I used to.
As there’s the greater possibility of being stuck in an infinite loop
 
For god sake man comment your work
I think the code is pretty self-explanatory. All the variables and member have meaningful enough names. If you have trouble understanding it, you should work on your ability to read foreign code. And I don't mean to be condescending. Reading foreign code fluently is one most important skills for a developer. Relying on comments to understand code is, IMHO, often not a good idea, since comments can be outdated, vage, incomplete, misleading or plainly wrong. That said, comments however can be a good idea if your doing something out of the ordinary like optimizations or advanced math.
But you should use for loops to loop a certain number of times eg: for i = 1 to 10 or for i = 1 to x
you shouldnt use for loops as a loop while condition is true or a loop until condition = false
I think if you use for or while/do while loops is mostly a matter of personal taste. I usually prefer for because you have initialization expression(s), exit condition and iteration expression(s) all in one line while the "business logic" is in the inner scope. That way it is better separated and easier to read, in my opinion at least.
ps: 0.0f is hex yes
No. Since Zed is using Unity, the programming language is clearly C#. That means 0.0f is a float (as denoted by the f postfix). A hex number would have a 0x prefix, e.g. 0xdeadbeef = 3735928559.
FWIW this is what I’m coding
That looks like really nice, oldskool fun! Any idea when it will be finished?
 
Finish date? I don’t even have a title yet!
But it’s coming along good, though regretting buying my pc, with intel onboard gfx, after coming from nvidia which is rock solid it’s painful, so unstable I have to reboot the pc, a few times a day which cuts down production time
 
Intel onboard graphics? Ouch! Punish yourself much? Can't you just buy a add-on graphics card? Or did you buy a mini-pc or something similar?
 
yes mini pc, I was looking into maybe getting a external graphics card something cheap nvidia 750 or something, but from looking external graphics seem more expensive than just buying a new PC. Unless someone knows of a cheap option?
 
Back
Top