Jump to content
UBot Underground

Best Way To Add Multiple Values


Recommended Posts

I have a bot that collects values from lots of sites. At the moment I am just creating a variable for each one and assigning the value for a site to a variable, so I will have lots of them (around 100)

 

Is there a quick and efficient way to add all those variables up to get a total sum? Using eval and add is messy when you're adding more than a few up?

 

Thanks

Link to post
Share on other sites

I have a bot that collects values from lots of sites. At the moment I am just creating a variable for each one and assigning the value for a site to a variable, so I will have lots of them (around 100)

 

Is there a quick and efficient way to add all those variables up to get a total sum? Using eval and add is messy when you're adding more than a few up?

 

Thanks

I would use a table with 2 columns. 1 column the site name and second column the data.

 

Then you can loop though the table and add the values from column 2.

 

Dan

  • Like 1
Link to post
Share on other sites

Here is a cool way to do it with Ubots Python.

 

The first to nodes are just an example of how to do it.

add list to list(%numbers,$list from text("1,2,3,4,5",","),"Delete","Global")
alert($run python with result("list_to_sum = ({$text from list(%numbers,",")})
the_Sum = sum(list_to_sum)
the_Sum"))
divider
comment("the function")
comment("funtion takes text")
alert($Sum a List("1,2,3,4,5", ","))
comment("function takes a list")
alert($Sum a List(%numbers, $new line))
define $Sum a List(#LIST_FROM_TEXT, #DELIMITER) {
    return($replace regular expression($run python with result("list_to_sum = ({$text from list($list from text(#LIST_FROM_TEXT,#DELIMITER),",")})
the_Sum = sum(list_to_sum)
the_Sum"),"(|)",$nothing))
}

Then I made a function to take either some test or Ubot list.

 

The first line of python takes ubot list and makes it into an Python list.

 

The second uses the sum() func of python and sticks it an variable.

 

Last line gives the result. in Python 2.7 the last line would look like this

print the_Sum

 

It is easier than it looks all by it self as a function.

 

Only good for Ubot 5 Devs.

 

Hope that helps,

 

CD

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...