playMaker

Author Topic: Finding the sum of an array?  (Read 1753 times)

Sunny

  • Playmaker Newbie
  • *
  • Posts: 12
Finding the sum of an array?
« on: June 21, 2017, 12:50:37 AM »
Hi! If I have an array of integers, how can I automatically find the sum of the array?

Here is an example:

(Now I get this)
Array 1
485, 325, 198, 225, 186

(But I want this as)
Array 1
485 + 325 + 198 + 225 + 186 = Int Variable

Is there a possible solution to achieve this in Playmaker? Thank you for any help or suggestion! Cheers!
« Last Edit: June 21, 2017, 01:06:27 AM by sunnwy »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Finding the sum of an array?
« Reply #1 on: June 21, 2017, 01:23:00 AM »
Hi,
you can loop this with "array get next" and use an int add.

If you don't know yet how to, you can find some tutorials here

Sunny

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Finding the sum of an array?
« Reply #2 on: June 21, 2017, 03:06:25 AM »
Hi!
Thanks for the quick reply! Very much appreciated!

I am doing the loop with "array get next" and storing the result as an Int variable, but still all I get is the current Integer in the array. (Integers adds up in some random seconds in the array)

Actually I am messed up in the loop state. When I use Int Add, I am using the variable that I stored earlier in the "array get next" state. and after this I am doing a finished event to the "array get next". So I think there is some important action or variable that I am missing in between to use!

Also as a quick note, I am following this tutorial somewhat to achieve my result.


I still need to fix this up in time! So, can you please help me with some more details on this.

Thank you!
« Last Edit: June 21, 2017, 03:14:43 AM by Sunny »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Finding the sum of an array?
« Reply #3 on: June 21, 2017, 08:18:24 AM »
Hi.
Quote
I am doing the loop with "array get next" and storing the result as an Int variable, but still all I get is the current Integer in the array. (Integers adds up in some random seconds in the array)
after you got that int you need to use 'int add' in the next state (the state you are looping to)
In 'int add' set a new int variable (call it 'result' for example) into 'Int Variable' and place the int variable that you got from the array into'Add'

Then connect a state to the 'finshed event' in that state you can use the 'result' variable that will have the total from the arrays.

if you need to do this again later in your game you need to 'reset' the 'result' value,
you can do this by using 'set int value' and set it to 0
in the link you can see some images on how to set this up :
https://ibb.co/gZCJk5

Sunny

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Finding the sum of an array?
« Reply #4 on: June 21, 2017, 12:46:59 PM »
Hi!

First of all, a many many big thanks to you for helping me out with this very very sweet and cute example of yours! I really couldn't believe, this was that sample! Actually, it isn't. but you made it look like that!! You are a genius! Thank you so much once again!

Also, I would like to be your patron too!! your works motivated me!

Playmaker is awesome, so are you!! Have a great day ahead!

Thanks & Cheers!!
« Last Edit: June 21, 2017, 12:49:07 PM by Sunny »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Finding the sum of an array?
« Reply #5 on: June 21, 2017, 09:32:26 PM »
H.
I am happy to help.

Btw you can find several tutorials on the User Tutorial Wiki page (beginner to advanced)
When i started using Playmaker it took a little while to get the hang of it, but the more you use it, the easier it gets, i even learned C# thanks to Playmaker and make my own custom actions.

If you are looking for custom actions (things you can't find in the standard actions)
you can get the Ecosystem.
You can find many actions, packages and samples there.

If you want to become a patron you can click on the patron text, it will forward you to my Patreon page.