addamroy 36 Posted May 8, 2012 Report Share Posted May 8, 2012 I'm in a situation where I'd like to be able to create variables...using variables. I'm talking the ACTUAL VARIABLE NAME, not the VALUE of the variable. Let me explain... I have a loop, the loop runs through a list, i want to set a unique variable during the loop for each item in the list. For example, I want these to create a series of unique variables. Let's say, this list has each letter of the alphabet as a separate item, a,b,c,d,e,f,g,h,i,j,k, etc So each time the loop runs, it will set variables like this, #AlphabetSet_A#AlphabetSet_B#AlphabetSet_C#AlphabetSet_D#AlphabetSet_E#AlphabetSet_F#AlphabetSet_Getc. I just can't figure any way, if there even is a way, to set dynamic variables. Like is there any way to do something along the lines of, set(#Alphabet, "some value", "Global")but include an additional variable that appends to #Alphabet? Maybe,,, set(#Alphabet+#currentlistitem, "some value", "Global")or something like that? Quote Link to post Share on other sites
addamroy 36 Posted May 9, 2012 Author Report Share Posted May 9, 2012 Anyone? WAs this a silly question? Is it possible at all?? Quote Link to post Share on other sites
Brutal 164 Posted May 9, 2012 Report Share Posted May 9, 2012 OP - I have been messing around with the DEFINE function, and if I understand you correctly, it seems that you could create your complex custom variables that way. I'm probably missing your point - so hopefully one of the really knowledgeable ubot people here will chime in. Quote Link to post Share on other sites
addamroy 36 Posted May 10, 2012 Author Report Share Posted May 10, 2012 Yep you missed it My define command does the following... Runs a loop for each item in a list... I need to set a variable for each list item each time the loop runs. Quote Link to post Share on other sites
Legend 181 Posted May 10, 2012 Report Share Posted May 10, 2012 Have you tried the "append line to text" text function parameter? http://ubotstudio.com/forum/public/style_emoticons/default/blink.gif Quote Link to post Share on other sites
addamroy 36 Posted May 10, 2012 Author Report Share Posted May 10, 2012 Duane, it's the variable NAME I need to create dynamically, maybe I should have specified that. I don't need to create the VALUES from the list, I need to create actual variables from them. I can't seem to find any way at all to set a variable name any other way than typing it in, i can't drag any nodes into it or anything. Quote Link to post Share on other sites
Praney Behl 314 Posted May 10, 2012 Report Share Posted May 10, 2012 Addam, Don't think Eddie allows it. I have tried doing such messy things a few times many moons ago, and we had huge discussions about this in the past. Buddy thought its just a bad idea LOL. But I see where you are coming from... Quote Link to post Share on other sites
Legend 181 Posted May 10, 2012 Report Share Posted May 10, 2012 Ah... gotcha... Never seen that done... good idea though! http://ubotstudio.com/forum/public/style_emoticons/default/cool.gif Quote Link to post Share on other sites
Randy Role 1 Posted May 10, 2012 Report Share Posted May 10, 2012 Forget it. :-) Quote Link to post Share on other sites
addamroy 36 Posted May 10, 2012 Author Report Share Posted May 10, 2012 aww man. Quote Link to post Share on other sites
JohnB 255 Posted May 10, 2012 Report Share Posted May 10, 2012 Correct...this is not possible. John Quote Link to post Share on other sites
Eddie Waller 158 Posted May 10, 2012 Report Share Posted May 10, 2012 Could you give a scenario where this would be useful? It seems to me in your example you are creating 26 new variables, one for each item in the list so you can use those variables later. But why would you use those variables instead of just using $list item? You won't be able to loop through those variables so you would have to use each of them one at a time, and if you are doing something similar with every variable, you would end up duplicating your main code 26 times. If you just used $list item, you would not have to duplicate any code. Hope that helps, let me know if you can give a scenario where this would be useful. It's not a very common language feature to dynamically name variables as it usually leads to hard to understand code. Quote Link to post Share on other sites
Praney Behl 314 Posted May 10, 2012 Report Share Posted May 10, 2012 I don't see a need for variable for variable name. But a little away from this, a good example where variables in the name of custom commands/function can cut down a lot of code by simple using user input lets say from a drop down menu into the command/funtion 's name. This would cut down the need for using several if/else statements in comparitively large scripts. Quote Link to post Share on other sites
Kreatus (Ubot Ninja) 422 Posted May 10, 2012 Report Share Posted May 10, 2012 This is the old thread about this http://ubotstudio.com/forum/index.php?/topic/6743-ability-to-use-variables-in-run-sub/ Quote Link to post Share on other sites
Eddie Waller 158 Posted May 10, 2012 Report Share Posted May 10, 2012 This is the old thread about this http://ubotstudio.co...les-in-run-sub/ That is a thread about running commands based on variables, this thread was created to address naming variables with other variables, which is a different concept. Quote Link to post Share on other sites
addamroy 36 Posted May 10, 2012 Author Report Share Posted May 10, 2012 Here's my current scenario I hope I can explain it easy enough... I have spreadsheet with 2 columns, one with the variable name, one with the variable value. The spreadsheet will always be different. (Each row is 1 item. Column 1 is variable name column 2 is variable value) What I want to do, is set a variable for each item in the list, and the VALUE for each item is just some HTML output. For example, let's say..... my spreadsheet columns were... URL and ANCHOR text. urls: google.com, yahoo.com, bing.com anchor text: google, yahoo, bing (pretend these are in a spreadsheet, urls is column 1 and anchor text is column 2) I want to create a 'token' for each variable created that I can use later. The script will REPLACE the token with the value of the variable associated with it. Example, First loop would set the following variables: $Item1_url = current URL in column 1 $Item1_anchortext = current anchor text in column 2 It will then, use these 2 variables to set ANOTHER variable, which will be the final HTML. $Item1_html = <a href="$Item1_url">$Item1_anchortext</a> Item1_html will have a 'token' of sorts outputted to the user. For example, something like, ==Item1== might be the token. Now, essentially what's going to happen is anywhere ==Item1== is in the document, the script will replace it with the value of $Item1_html. I need to actually, 'create' variables which will always be unique dependent on what's in the list. ======== essentially if i could put it as simply as i possibly can.... Unless I can create variables within a loop, I'll have to manually create a set variable for each possible entry in the list. If there's 10 items in a list, and I need a variable for each one, that means I need to manually set 10 variables outside the loop for each item. If there's 100 items in a list, and I need a variable for each one, I'll have to manually create 100 variables outside the loop for each item. Quote Link to post Share on other sites
JohnB 255 Posted May 10, 2012 Report Share Posted May 10, 2012 You don't need to name the variables...just add the items to a list along with the appropriate html add item to list<a href="$table cell>$other table cell</a>does that make sense?John Quote Link to post Share on other sites
addamroy 36 Posted May 11, 2012 Author Report Share Posted May 11, 2012 Yep makes sense, thanks. But the hard part is 'after' I have that last variable. The HTML you provided is essentially the value of $item1_html in the example above. But the 'token' that's output to the end user will essentially be a placeholder for that value. The token for each list item could be placed anywhere, the script is going to search and replace the token with it's corresponding variable value. I could ad the item1_html to a list instead of setting it as a variable but it doesn't do me any more good in a list than it does in a variable. Either way the reasons behind my wanting to do this probably makes it sound more complicated than it needs to be haha Idk maybe I'm crazy... I just need to create a variable within a loop for each item in a list automatically somehow... Creating a variable WITHIN a loop is in fact the clincher. Creating a variable within a loop is a tricky thing! If not impossible! Quote Link to post Share on other sites
addamroy 36 Posted May 11, 2012 Author Report Share Posted May 11, 2012 Even if I had the ability to append an incrementing value to the end of the variable names in a loop... So if we were going off just one column in the my list example... The loop might generate the following variables as it runs the loop, assuming there's 3 items in the list. $url_1 = google.com$url_2 = yahoo.com$url_3 = bing.com Imagine having the ability to append an incrementing, or other dynamic value to the end of a variable... Now I have 3 set variables I can use later on..., all created with a loop. Quote Link to post Share on other sites
Eddie Waller 158 Posted May 11, 2012 Report Share Posted May 11, 2012 You're basically recreating the concept of a list without wanting to use one. You are wanting to loop through #html_0, #html_1, #html_2 after dynamically creating them, when you could just add the values to a list %html and use $list item(%html, 0) $list item(%html, 1) and $list item(%html, 2) You can even search for __ITEM_0__ and replace it with the first item in the list, just have a loop incrementing #index and $replace(text, "__ITEM_{#index}__", %list item(%html, index)). Hope that makes sense. Quote Link to post Share on other sites
addamroy 36 Posted May 11, 2012 Author Report Share Posted May 11, 2012 Well if I use a list, I'm forced to use those list items in order right? Next list item, previous list item, or set list position then next list item. Quote Link to post Share on other sites
addamroy 36 Posted May 11, 2012 Author Report Share Posted May 11, 2012 Maybe I just have to get a little more creative..... Quote Link to post Share on other sites
Praney Behl 314 Posted May 11, 2012 Report Share Posted May 11, 2012 Well if I use a list, I'm forced to use those list items in order right? Next list item, previous list item, or set list position then next list item. You can think out of the box and create the lists dynamically depending upon user input Playing with lists is much easier than else... Quote Link to post Share on other sites
Eddie Waller 158 Posted May 11, 2012 Report Share Posted May 11, 2012 Well if I use a list, I'm forced to use those list items in order right? Next list item, previous list item, or set list position then next list item. You can use list items in any order you want, by using the $list item function and specifying the index of the item. Quote Link to post Share on other sites
addamroy 36 Posted May 11, 2012 Author Report Share Posted May 11, 2012 this isn't working lol, I need some way to have dynamic variable names. Or call them dymanically. Here's a perfect example. I've got a bunch of checkboxes, if then else for each of them. All these checkboxes are in the UI html panel. right now there's about 10 of them but there eventually might be 100 of them. example here... stove: <input variable="#google" type="checkbox" fillwith="checked"> <input variable="#yahoo" type="checkbox" fillwith="checked"> <input variable="#bing" type="checkbox" fillwith="checked"> if box is checked, do this and that.... I gotta do this for EACH checkbox... How do I... Check if a checkbox is checked, where the checkbox it's looking for is the next list item. for each checkbox, I have 1 entry in the list. If I have 10 checkboxes, I have 10 entries in the list. So how do I create a loop, (a single set of commands), that will allow me to check if each checkbox is checked... each item in the list is identical to the variable name appended to each checkbox. I'm trying to use this list to automate the endless if-then-else statements associated with checkboxes using a loop. I have to do it someway like this... within the loop... Example list, google,yahoo,bing set #current_item = $next list item (some list) // at this point, first run of the loop, variable #current_item = google. Remember for each checkbox, there is an entry in a list. As I update the checkboxes I update the list // If > comparison (#current_item = true) > then.... You can't, because the result of #current_item outputs as the value of the variable, not the variable. So it would essentially be, saying > if google = true, and not if #google = true (#google would be the variable attached to the checkbox) of course you can't do this either, If > comparison (##current_item = true), I'd like to think that it would just append the extra # to the #current_item result but you can't do that. If I could however dynamically CREATE these variables from the list, I could automate an entire, if not endless flow of if-then-else statements with a single loop. Am I making sense? Think about it, there isn't even a way to call a variable dynamically, you have to call a set variable. Like, you can't say, load variable #($next list item) here from what I can tell. Having this ability would open a ton more doors and automation capabilities. So yea even being able to call variables dynamically would be just as valuable as being able to set them that way, but more powerful if you could do both. 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.