| 11-01-2006, 01:01 AM | #1 |
I am trying to make a system for Wc3 and so far I have only one problem, ill give a quick example of what my problem is lets say there is a function that when you call you have a string as an argument that has multiple options, something like this JASS:call RandomFunction("Group A = Jack+Jill, Group B = Susan + Sally") When the actual function is being called how would you detect the seperate string. Lets suppose we have 2 string arrays, one that will hold all the values in Group A and one that will hold all the values in Group B i.e. JASS:function RandomFunction takes string s returns nothing local array string GroupA local array string GroupB What would you do after this so in the array Group A you would get in index 1, Jack and Index 2 Jill and in Group B in index 1 you would get Susan and Index 2 you would get Sally. The order isn't important but there isnt going to be a set number of options you can enter. I want the system so you can enter as many options as you want and the function will detect when to reach the end |
| 11-01-2006, 01:26 AM | #2 |
Sorry if I don't understand what you're talking about. So what you want is that say you have Group A containing Jack + Jill, and Group A has 2 indexes; Index 1 shows Jack + Jill and Index 2 shows Jack/Jill? Then why not just create another variable to show Jack/Jill? |
| 11-01-2006, 01:41 AM | #3 |
No No No When you called the function with a string, i want to be able to detect all the options that was entered into the string in the argument for the function that was called So basically I want to be able to get: GroupA[1] = Jack GroupA[2] = Jill GroupB[1] = Susan GroupB[2] = Sally in the RandomFunction. Obviously you would use a loop for the indexes and to be able to detect when you reach the last option |
| 11-01-2006, 01:49 AM | #4 |
call RandomFunction("Group A = Jack+Jill, Group B = Susan + Sally")
And why wouldn't you simply use multiple arguments? Also, if you really need to, you can regulate the length of each individual series of characters. So if you knew you'd have 8 characters for each 'series' in the concatenated string -- JASS:function RandomFunction takes string s returns nothing local string array series local integer index = 0 local integer ends = StringLength(s) loop exitwhen index >= ends set series[(index/8)] = SubString(s, index, index+8) set index = index + 8 endloop //Do stuff to your string array. endfunction So yeah. |
| 11-01-2006, 01:56 AM | #5 |
Well i dont want to use multiple arguments because I want no limit to the number of values that the function can take, which is why it is in the form of the string. i.e. I want a person to be able to enter lets say 2 options, or maybe 7 options in the same function, i need the amount of arguments to be varied |
| 11-01-2006, 01:59 AM | #6 |
If you set a limit like 21 strings you could use things like dynamic arrays. Else just use tokenizing, I don't really get the sense of the Group A and Group B thing you need to parse it, so just do it. |
| 11-01-2006, 02:37 AM | #7 |
Is the data part of the script or is it input ingame? If it's in game, use a single character token to delimit values, like "a,b,c". If it's part of the script and you really need a function to take multiple arguments, use a stack or array NOT STRINGS! |
