coding problem

Discussion in 'General Discussion' started by zed, Apr 25, 2019.

  1. zed

    zed
    Veteran

    Joined:
    Dec 16, 2005
    Messages:
    4,387
    Likes Received:
    599
    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
     
    #1 zed, Apr 25, 2019
    Last edited: Apr 25, 2019
  2. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    14,785
    Likes Received:
    2,210
    For god sake man comment your work
     
  3. zed

    zed
    Veteran

    Joined:
    Dec 16, 2005
    Messages:
    4,387
    Likes Received:
    599
    no time for comments , though seriously I do occasionally place comments in, though more along the lines of WTF, etc
     
    McHuj likes this.
  4. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    14,785
    Likes Received:
    2,210
    put a breakpoint just before put a watch on the variable you want and step through

    because you don't have a variable called height
    edit:
    yes you do and you've assigned it a value of 0.05859375
     
    #4 Davros, Apr 26, 2019
    Last edited: Apr 26, 2019
  5. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    14,785
    Likes Received:
    2,210
    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;
     
  6. BRiT

    BRiT (╯°□°)╯
    Moderator Legend Alpha Subscriber

    Joined:
    Feb 7, 2002
    Messages:
    12,162
    Likes Received:
    8,316
    Location:
    Cleveland
    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.
     
  7. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    14,785
    Likes Received:
    2,210
    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 ?
     
  8. zed

    zed
    Veteran

    Joined:
    Dec 16, 2005
    Messages:
    4,387
    Likes Received:
    599
    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
     
  9. BRiT

    BRiT (╯°□°)╯
    Moderator Legend Alpha Subscriber

    Joined:
    Feb 7, 2002
    Messages:
    12,162
    Likes Received:
    8,316
    Location:
    Cleveland
    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.
     
  10. Davros

    Legend

    Joined:
    Jun 7, 2004
    Messages:
    14,785
    Likes Received:
    2,210
    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 ?
     
  11. BRiT

    BRiT (╯°□°)╯
    Moderator Legend Alpha Subscriber

    Joined:
    Feb 7, 2002
    Messages:
    12,162
    Likes Received:
    8,316
    Location:
    Cleveland
    I disagree with that statement.
     
  12. Malo

    Malo Yak Mechanicum
    Legend Veteran Subscriber

    Joined:
    Feb 9, 2002
    Messages:
    6,908
    Likes Received:
    2,972
    Location:
    Pennsylvania
    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.
     
  13. zed

    zed
    Veteran

    Joined:
    Dec 16, 2005
    Messages:
    4,387
    Likes Received:
    599
    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
     
  14. N00b

    Regular

    Joined:
    Mar 11, 2005
    Messages:
    683
    Likes Received:
    100
    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.
    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.
    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.
    That looks like really nice, oldskool fun! Any idea when it will be finished?
     
  15. zed

    zed
    Veteran

    Joined:
    Dec 16, 2005
    Messages:
    4,387
    Likes Received:
    599
    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
     
  16. N00b

    Regular

    Joined:
    Mar 11, 2005
    Messages:
    683
    Likes Received:
    100
    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?
     
  17. zed

    zed
    Veteran

    Joined:
    Dec 16, 2005
    Messages:
    4,387
    Likes Received:
    599
    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?
     
Loading...

Share This Page

  • About Us

    Beyond3D has been around for over a decade and prides itself on being the best place on the web for in-depth, technically-driven discussion and analysis of 3D graphics hardware. If you love pixels and transistors, you've come to the right place!

    Beyond3D is proudly published by GPU Tools Ltd.
Loading...