Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: MichaelPatriot21 on May 12, 2019, 08:46:00 PM

Title: Integer Array Average
Post by: MichaelPatriot21 on May 12, 2019, 08:46:00 PM
If I make an array of intergers, how would I go about getting an average and storing it in a global variable? I'm making a grand strategy game, each country has a reputation with your organization. So I want to make an array of all the North American countries' relationship with you and display the average relationship you have with North America.
Title: Re: Integer Array Average
Post by: djaydino on May 13, 2019, 04:54:52 PM
Hi.
You can loop thru the array with 'Array get next' and add all the int's into a variable (call it 'Total' for example)

Then get the length of the array with 'Array Length'.

Then use a float operator and divide the Total by the array length. and store in a float variable.

Then if you wish you can use 'Convert Float To Int' and you can select the 'Rounding' you wish.
Title: Re: Integer Array Average
Post by: MichaelPatriot21 on May 13, 2019, 05:17:36 PM
Thank you, this is what I was looking for.