1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Better way to set a row variable

Discussion in 'Programming' started by TheNegroShoddy, Feb 14, 2020 at 11:35 PM.

  1. TheNegroShoddy

    TheNegroShoddy Member

    Joined:
    Jul 11, 2016
    Posts:
    433
    I'm currently in the middle of coding the menu in an RPG where a character's spells are displayed and have ran into a small problem. All spells are stored in an array and the spells are shown on screen in rows of two like in Final Fantasy 6. I'm trying to come up with a way to always get the correct number of rows based on the amount of spells a character has.

    My first thought was to just take half of the array length:

    Code:
    total_spell_rows = ( array_length_1d( global.char_battle_info[ CHAR_BATTLE_PROP.CBP_SPELLS, char_sel_party_pos ] ) /  2 );
    
    However, in some cases this would lead to an inaccurate number of rows unless I use the round() function. I was just wondering if there was a better way to do this.
     
  2. Nidoking

    Nidoking Member

    Joined:
    Nov 20, 2019
    Posts:
    114
    That's pretty much how you do it - I use the ceil() function to ensure that I round up and create the extra row, but that's exactly how you determine the number of rows.
     
    TheNegroShoddy likes this.
  3. TheNegroShoddy

    TheNegroShoddy Member

    Joined:
    Jul 11, 2016
    Posts:
    433
    Oh, okay I just wanted to make sure there wasn't a better way to do this. I'm not familiar with ceil() since I mostly stick with using round(). Just read up on both functions, and you're right its better to use ceil since with the round() function due to the banker's rounding thing. Thanks for the quick reply.
     

Share This Page