Jump to content
UBot Underground

Increment Variable With Variable Value?


Recommended Posts

I'd like to increment a variable based on the value of another variable.

 

 

an example:

on load("Bot Loaded") {
    set(#table_item_counter,0,"Global")
    create table from text(&item_table,"item=2,cat
item=1,dog
item=4,horse
item=3,fish")
}
set(#current_item,"item=2","Global")
define resolve_item {
    set(#current_item_table_index,$plugin function("TableCommands.dll", "$table search", &item_table, #current_item, "Row Index"),"Global")
    set(#current_item,$table cell(&item_table,#current_item_table_index,1),"Global")
}
increment(#value_of_current_item)

In this case, I'd want to increment the variable "#cat"  If #current_item had been set to "item=4", i'd want to increment "#fish" and so on.

 

the idea is that I'm using a table search to match a value (call it #A), and to set another value from that table using the row index from the search.  I want to then increment an already created variable (one of several) so I can find out how many particular items there are in that table.  

 

I tried the same idea using lists, but you cant use a function inside of an "add to list" command (what list to add to), and I'm seeing the same problem here..

 

 

 

If anyone has any ideas or insight, or alternatives for what I'm trying to accomplish, i'd really appreciate it. 

Link to post
Share on other sites

I tried the same idea using lists, but you cant use a function inside of an "add to list" command (what list to add to), and I'm seeing the same problem here..

 

You need to use list from text in the list to add to then put anything you want in there.

 

Anyways, this all sounds a bit confusing. What exactly do you want to get? The number of cats, dogs, etc in the table?

Link to post
Share on other sites

 

 

You need to use list from text in the list to add to then put anything you want in there.

I mean for the list name of items to add to, not for the values.

 

 

Anyways, this all sounds a bit confusing. What exactly do you want to get? The number of cats, dogs, etc in the table?

exactly.  I've got a larger table with a possibility of 72 different entries, and i'm scraping item ID's.  I want to resolve those ID's (column0) to their names (column1), and increment how many of each there are in the table.  Sorry for the confusing wording, I'm not quite sure how to phrase it any better lol.

 

You seem to get where i'm going with this, got any better ideas for implementation?  I'm sure there is a better way to do this I'm just completely missing.  I've thought about SQL, but to be perfectly honest, I'm not very well versed in SQL, and preceding attempts to use it have been... messy at best?  

 

Thanks for any ideas or input as usual!

Link to post
Share on other sites

So this is a brief example of how you can get the items into a list and then subtract a list of what you want (the current item) and then get the count of that item. If you need help turning it into a function let me know. The thing I'm still not sure of is the part where you say you want to resolve the IDs. Are they always the same for that item? Like is a fish always 3?

clear table(&item_table)
create table from text(&item_table,"item=2,cat
item=1,dog
item=4,horse
item=3,fish
item=2,cat
item=4,horse
item=3,fish
item=4,horse
item=4,horse
item=3,fish
item=3,fish
item=3,fish")
clear list(%tableItems)
add list to list(%tableItems,$plugin function("TableCommands.dll", "$list from table", &item_table, "Column", 1),"Don\'t Delete","Global")
clear list(%subtractedList)
add list to list(%subtractedList,$subtract lists(%tableItems,$list from text("fish","
")),"Don\'t Delete","Global")
set(#total,$subtract($list total(%tableItems),$list total(%subtractedList)),"Global")
Link to post
Share on other sites
  • 3 weeks later...

Yeah.  The Item ID's are static, and I'm matching them to id's i'm scraping from profiles.

 

so while I'll have these static values:

 

item=1,dog
item=4,horse
item=3,fish
item=2,cat

 

I'll be scrapping hundreds of each, which I want to count.  So I've scraped 10x "item=1", 5x "item=4", 2x "item=3" and 1x "item=2".  Which leads us back to my original goal:  I want to tally the total of each matching item.

Link to post
Share on other sites
  • 1 month later...

I am a complete coding novice so forgive me for the parts you will have to fill in yourself. In javascript (the language I am slowly learning) if you set four variables; tally1, tally2, tally3, tally4), then you could create four expressions to increment each variable by 1 for each exact match (each time Dog appears in the HTML tag you specify). And then you woukd end up with a tally for each variable

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...