So, I have an array of buttons, but currently, they don't do anything. I have them hooked up to an event. But I don't know how to distinguish between each of the buttons. Is there a way to get the text on the button or some other means of identification?
You'll have to compare it to the buttons you have from your array. Depending on how many buttons you have you might want to use another if or (since you're using an array I guess you have more that a view buttons) a switch function:
I doubt that this is a one liner, maybe in galaxy but not with the GUI. Since I'm mostly using the GUI I might not be able to help you with that.
But I'll see what I can do ....
Well (Used Dialog Item) should be an object that is a DialogItem, which is also an object. Since these objects have fields upon creation, the fields should be accessible after creation.
I just wish there was a way to view the documentation for each object in the editor, like any other programming language. =\
Unfortunately it isn't that easy.
You can't convert a Dialog Item's label into an int, because it's of type Text. Text cannot be converted to anything.
So basically you would have to use a switch statement like Hobrow suggested or something similar.
I don't know if I understood you correctly, but here is something you could try:
Events:
Dialog - Any Dialog Item is used by Player Any Player with event type Clicked
Local variables:
i = 0 <Integer>
Conditions:
Actions:
For each integer i from 0 to 50 with increment 1, do (Actions)
General - If (Conditions) then do (Actions) else do (Actions)
If
(Used dialog item) == YourButtonArray[i]
Then
Do whatever you like
General - Break
Else
The 50 is just a number i chose. It should be the number of the last index of your array.
You cannot convert text to anything, because text is localized and might be different for different players. If you were able to convert it, this could cause desyncs and crashes.
For this reason, there is only one-way conversion to text, and the stuff you can do with text is very limited. Also Blizzard announced, there are no plans for adding an option to convert text to anything else.
If you want to store something in your dialog items, just use an array or the data table or whatever. A dialog item is just an integer, in galaxy script you can use it like one; not sure, if you can do the same in gui.
Something like this would work in galaxy (its pseudocode, though)
You could call the foobar function in a trigger, which triggers when pressing any of the buttons, use the used dialog item as parameter and it would print the respective array slot.
I've created something similar in my map, have a look at it, if you think this is what you need, basically i created 12 different dialog's so each dialog is different to the player. and to do that i made a variable like ' [Dialog] = <Last Created Dialog> [12][8] '
The 12 means which player's dialog will be affected, and the 8 is how many slots are on each dialog, so basically if player 7 catches a fish, so it would be set [Dialog][7][1]... It's fairly simple, but can be confusing.
as Kueken said: TextToString does not exist. it is impossible what you want to do the way you want it to do. Galaxy is very limited. I'm always getting a headache as i'm used to java
Thanks, guys, you've all been super helpful. The wiki says that the create dialog item thing returns a control, which I had no idea was an int.
So what I did, was change my array to, instead of storing the location id as the index to the array, I've put the dialog items themselves as the index to the array.
So.. now I do array_name[DialogBUtton] = location_index =D
So, I have an array of buttons, but currently, they don't do anything. I have them hooked up to an event. But I don't know how to distinguish between each of the buttons. Is there a way to get the text on the button or some other means of identification?
Use "Used Dialog Item"
@Hobrow: Go
But How do I know which Dialog Item was clicked?
Like... If I only use Used Dialog Item, then all my buttons do teh same thing. =\
That sounds very stange I suggest that you post your code. Apparently I can't guess where the problem is without seeing the code ;)
@Hobrow: Go
http://dl.dropbox.com/u/331982/Help/StarCraft/Editor/DiffertiationBetweenButtonsInAnArrayWhenClicked.png
The part where I need to differentiate between the buttons is in the else block.
Like... If I could do
TextToInt((Used Dialog Item).text)
I would be golden.
You'll have to compare it to the buttons you have from your array. Depending on how many buttons you have you might want to use another if or (since you're using an array I guess you have more that a view buttons) a switch function:
@Hobrow: Go
I don't need to use a switch function, because All I need is the value of the button =D. No point in having 24 lines of extra code.
What I want in my else statement is this:
Somehow set the starting location of the player to the TextToInt value of the button text.
should be a one liner.
I doubt that this is a one liner, maybe in galaxy but not with the GUI. Since I'm mostly using the GUI I might not be able to help you with that. But I'll see what I can do ....
@Hobrow: Go
Well (Used Dialog Item) should be an object that is a DialogItem, which is also an object. Since these objects have fields upon creation, the fields should be accessible after creation.
I just wish there was a way to view the documentation for each object in the editor, like any other programming language. =\
EDIT: just found the wiki page for Used Dialog Item: http://www.sc2mapster.com/wiki/galaxy/triggers/used-dialog-item/ But it is incomplete
Unfortunately it isn't that easy.
You can't convert a Dialog Item's label into an int, because it's of type Text. Text cannot be converted to anything.
So basically you would have to use a switch statement like Hobrow suggested or something similar.
@s3rius: Go
False. Text can be parsed. Take a look at Java's Integer.parseInt(<string>); or ruby's string.to_i
Shirley, there is something similar in the galaxy editor.
http://www.sc2mapster.com/forums/development/triggers/19170-returning-array/
Does this help?
@Exaken: Go
It's essentially the same as using a switch statement. Except less lines of code. Same inefficiency though.
There is a parseInt(String foo) in Galaxy but not a parseInt(Text foo). Blizz did simply not add it. My guess is to prevent players from being kicked.
The loop is actually only as good as switch, if you add a break to the loop and soul did not in Exaken's post
@b0ne123: Go
Thanks for the parseInt. I'll probs just do parseInt(TextToString(ououaouoeu)) or something like that, if I need to.
I really shouldn't need the loop though.
Like... lets say I have DialogItem a, which has the button text saying "8".
I should be able to do something similar to parseInt(a.text)
I've tried a couple things: .getText(), .text(), buttonText, and .Text()
\
@DerNalia: Go
I don't know if I understood you correctly, but here is something you could try:
Events: Dialog - Any Dialog Item is used by Player Any Player with event type Clicked Local variables: i = 0 <Integer> Conditions: Actions: For each integer i from 0 to 50 with increment 1, do (Actions) General - If (Conditions) then do (Actions) else do (Actions) If (Used dialog item) == YourButtonArray[i] Then Do whatever you like General - Break Else
The 50 is just a number i chose. It should be the number of the last index of your array.
@DerNalia: Go
You cannot convert text to anything, because text is localized and might be different for different players. If you were able to convert it, this could cause desyncs and crashes.
For this reason, there is only one-way conversion to text, and the stuff you can do with text is very limited. Also Blizzard announced, there are no plans for adding an option to convert text to anything else.
If you want to store something in your dialog items, just use an array or the data table or whatever. A dialog item is just an integer, in galaxy script you can use it like one; not sure, if you can do the same in gui.
Something like this would work in galaxy (its pseudocode, though)
You could call the foobar function in a trigger, which triggers when pressing any of the buttons, use the used dialog item as parameter and it would print the respective array slot.
I've created something similar in my map, have a look at it, if you think this is what you need, basically i created 12 different dialog's so each dialog is different to the player. and to do that i made a variable like ' [Dialog] = <Last Created Dialog> [12][8] '
The 12 means which player's dialog will be affected, and the 8 is how many slots are on each dialog, so basically if player 7 catches a fish, so it would be set [Dialog][7][1]... It's fairly simple, but can be confusing.
http://starcraftmapping.de/gui.php?id=81
@Pshyched: Go
this is actually not a good solution.
just use 1 dialog and change it for player i instead of 12 dialogs
http://pastebin.com/z89d7cSx
@DerNalia: Go
as Kueken said: TextToString does not exist. it is impossible what you want to do the way you want it to do. Galaxy is very limited. I'm always getting a headache as i'm used to java
Thanks, guys, you've all been super helpful. The wiki says that the create dialog item thing returns a control, which I had no idea was an int.
So what I did, was change my array to, instead of storing the location id as the index to the array, I've put the dialog items themselves as the index to the array.
So.. now I do array_name[DialogBUtton] = location_index =D
le code:
And in the dialog item used event,
thank you all! ♥