so basically what i want to do is read out the string value of a preset, if possible.
after a short time of searching i found out that the editor already has a function for this implemented, called "Convert Preset to String", that needs a preset as parameter, whats quite strange because normally it should need a second parameter specifiing the index, cause a preset can have multiple values, or is it supposed to read out the name of the preset type?!
however, this function seems very strange.
1) in fact presets are integers or whatever, if you look at galaxy code a preset is just an integer, nothing more, so what does this function do? convert an integer to a string? if yes, this function isnt needed cause there is a function called integer to string.
2) in gui, this function doesnt accept any variables, even if its a preset variable. now it gets even stranger: you can select a value, and after reopening the window u can pick the preset variable.
3) when you try to compile the code it will give u a syntax error telling u that the parameter does not match the needed parameter, even if its a preset.
4) now it gets even worse: if you look at the galaxy code the "function" just doesnt exist. it just consists of "()" without any function name like "PresetToInteger" or anything. its just not there. entering it manually gives a syntax error telling u that this function doesnt exist.
so... how can i get the string associated with a preset value? is it even possible?
background is that i need to get the NAME of the key pressed.
what im also wondering is: there is a function called "KeyPressed()" that returns a preset of type key. if you use this condition and look at galaxy code it doesnt say for example "KeyPressed() == 10" but says "KeyPressed() == c_KeyA" for example.
im really confused cause for me presets are just integers in galaxy. so if this function returns an integer how can this be a valid line? also, if this is a valid line it must be possible to read out c_KeyA from the preset, doesnt it?
generally im quite confused about presets atm :D
so can someone explain what a preset exactly is and if its possible to get the string values associated with it? or get the name of the key pressed? for sure i could write an own "key to string" func with a very big switch statement but i dont really want to do that because there are alot of keys ~
A preset key is not a string. The base type is an integer, thats why the integer comparison works and the ConvertPresetToString doesn't.
The PresetToXX are merely helper functions for Gui; in Jass you can enter the number directly or use the constant itself; no conversion needed.
In theory, you can use strings as presets as well, which is, where the conversion function comes in. However, I have not see any string presets yet; at least not in blizzard's script.
Well, too bad for you, no direct correlation between the string "a" and the actual a key or the c_KeyA constant.
Well, too bad for you, no direct correlation between the string "a" and the actual a key or the c_KeyA constant.
Not too hard to make one though.
//const int c_keyA = 13;//const int c_keyZ = 38;conststringALL_KEYS="abcdefghijklmnopqrstuvwxyz";stringReturnPressedLetter(intkey){if(key>=13&&key<=38){returnStringSub(ALL_KEYS,key-12,key-12);//index is 1-based}else{return"Whatever the key was, it's not a letter. So don't pester me again.";}}
PS: I'm a bit wasted now so I honestly didn't really read the posts fully - sorry if that wasn't the issue. :D
ok sirius, well, this method is not much faster than just using a big switch statement and checking the preset value.
thats how i did it now.
additionally i dont just need letters, i need all possible keys what would be hard to do with your method, for example "control" would consist of more than 1 char what would mess up your func.
anyways, sad that we cant get the string associated with a specific index value of the preset, seems like that string is just some gui feature and cant be found in the code itself.
its also strange that you cant find a custom preset in your code, what seems to show that presets do only "really" exist in gui
PS: it took like 15min to make the function cause there are really ALOT of keys, but its done now lol
Algorithms like this is always faster than a big if-then-else chain! (@shakes his hand around like a mad proffessor@).
So you can use this way to identify numbers and letters and add all other controls manually.
Or you can do this:
//I dont think you can declare arrays like that in Galaxy? Probably needs to be done one-by-one instead x.xconststring[100]KEY_STRINGS={"A","B","C",..."0","1",..."Alt","Delete",...}//So basically like thatKEY_STRINGS[0]="A";KEY_STRINGS[1]="B";...stringReturnPressedLetter(intkey){returnKEY_STRINGS[key];}
This method is random-access. Basically can't get any faster.
Much better performance than a switch. At least how Blizzard implemented a switch. In real IDEs a switch would be just as fast.
And memory-wise it's the same too. Maybe even less memory-consuming.
PS: And yes, presets only exist in GUI.
However, Galaxy has a very similar kind of thing called typedef ( = type definition ) which allows up to map new names to existing types:
typedefintPotatoes;constPotatoesALL_MY_POTATOES=999;constPotatoesNO_POTATOES=0;intGetMyPotatoes(Potatoesi){returni;}stringHowManyPotatoes(Potatoesi){Potatoesp=i-1;//We steal a potatoe :3if(p==ALL_MY_POTATOES){return"HOLY BATMAN! WE GOT LOTS OF POTATOES!"}else{return"Construct additional pylotatoes."}}
however, where is the sense of this typedefs? why should i want to rename a variable type?
seems quite pointless to me :D
about performance, well, i dont think my switch statement will have real bad influence on map performance, so this is really not so important. there are much worse triggers. i just wanted the fastest and most confortable way for myself. another problem with doing this like you did is that your array must have the exact same keys for each index than the preset has, so you could easily save the wrong key in a specific index, as a very simple example if you say keys[0] = "B" and keys[1] = "A" you would get B if you press A key, it could get quite confusing for the special keys like control or alt. (@shakes his hand around like a mad proffessor@).
i think both methods have their own advantages, yours is faster while mine is more confortable.
Why you would want typedefs are probably to make the code more readable.
A well example would be, say Dialogs and DialogControls. Both represent integers.
Say you make a custom function which is supposingly going to take a DialogControl as parameter, but when calling the function you make a mistake putting the Dialog id there instead. If the parameter name wouldn't have been very explanatory, using typedefs to explicitly ask for a type instead of just some integer, it could lead to less errors in the code.
Now, in galaxy maybe they didn't implement typedefs very well, because even though you create typedefs, they are still a representative of the base type.
So the compiler would accept a dialog typedef even though the function requires a dialogcontrol typedef, while in most other compilers, this wouldn't be valid to compile.
Typedefs are like structs. Basically useless because you can do the same without them. Useful for organizing your code though, so it's easier to understand:
It helps you to not accidently enter wrong values and stuff.
Honestly it isn't really useful because we're missing so many things in Galaxy.
In real languages it makes more sense :p
PS: You can also make typedefs for structs, not only for primitives (I think).
But since you can't pass around structs it is of absolutely no fucking use.
So the compiler would accept a dialog typedef even though the function requires a dialogcontrol typedef, while in most other compilers, this wouldn't be valid to compile.
Visual studio allows this, as both types boil down to being a int. So probably all/most C+ + compilers allow it. C# is more restrictive, I think.
This is off topic.. but s3rius, I swear you're like a guru to me. Every time you make a post, I learn new programming techniques and my coding style evolves >_> All hail to thee. One day, I aspire to be a programming god like you :D
Say you make a custom function which is supposingly going to take a
DialogControl as parameter, but when calling the function you make a
mistake putting the Dialog id there instead. If the parameter name
wouldn't have been very explanatory, using typedefs to explicitly ask
for a type instead of just some integer, it could lead to less errors in
the code.
well, but normally the parameter name does that job, for exmaple "int DialogControl" would make clear that a dialog control is required, not a dialog.
its not a real difference if you got "DialogControl DC" instead of that imo.
same about sirius example... instead of calling the parameter "team t" i could also say "int team" what would be descriptive, too.
but i get your points, everyone should code like he wants to, but for me in galaxy this typedefs are not necessary.
Well, in that case it is a matter of preference I guess. But I think, just like in the trigger editor alot of types there are just native types in disguise (actorlink, etc) it could make it more understandable. While those disguised types there are not really needed, and does not really use typedefs (as the editor preprocessor is automatically correcting it) they would probably be alot more confusing to work with if presets of those fake types didn't exist.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
hi guys,
so basically what i want to do is read out the string value of a preset, if possible.
after a short time of searching i found out that the editor already has a function for this implemented, called "Convert Preset to String", that needs a preset as parameter, whats quite strange because normally it should need a second parameter specifiing the index, cause a preset can have multiple values, or is it supposed to read out the name of the preset type?!
however, this function seems very strange.
1) in fact presets are integers or whatever, if you look at galaxy code a preset is just an integer, nothing more, so what does this function do? convert an integer to a string? if yes, this function isnt needed cause there is a function called integer to string.
2) in gui, this function doesnt accept any variables, even if its a preset variable. now it gets even stranger: you can select a value, and after reopening the window u can pick the preset variable.
3) when you try to compile the code it will give u a syntax error telling u that the parameter does not match the needed parameter, even if its a preset.
4) now it gets even worse: if you look at the galaxy code the "function" just doesnt exist. it just consists of "()" without any function name like "PresetToInteger" or anything. its just not there. entering it manually gives a syntax error telling u that this function doesnt exist.
so... how can i get the string associated with a preset value? is it even possible?
background is that i need to get the NAME of the key pressed.
what im also wondering is: there is a function called "KeyPressed()" that returns a preset of type key. if you use this condition and look at galaxy code it doesnt say for example "KeyPressed() == 10" but says "KeyPressed() == c_KeyA" for example.
im really confused cause for me presets are just integers in galaxy. so if this function returns an integer how can this be a valid line? also, if this is a valid line it must be possible to read out c_KeyA from the preset, doesnt it?
generally im quite confused about presets atm :D
so can someone explain what a preset exactly is and if its possible to get the string values associated with it? or get the name of the key pressed? for sure i could write an own "key to string" func with a very big switch statement but i dont really want to do that because there are alot of keys ~
A preset key is not a string. The base type is an integer, thats why the integer comparison works and the ConvertPresetToString doesn't.
The PresetToXX are merely helper functions for Gui; in Jass you can enter the number directly or use the constant itself; no conversion needed.
In theory, you can use strings as presets as well, which is, where the conversion function comes in. However, I have not see any string presets yet; at least not in blizzard's script.
Well, too bad for you, no direct correlation between the string "a" and the actual a key or the c_KeyA constant.
Not too hard to make one though.
PS: I'm a bit wasted now so I honestly didn't really read the posts fully - sorry if that wasn't the issue. :D
thanks for your replies.
ok sirius, well, this method is not much faster than just using a big switch statement and checking the preset value.
thats how i did it now.
additionally i dont just need letters, i need all possible keys what would be hard to do with your method, for example "control" would consist of more than 1 char what would mess up your func.
anyways, sad that we cant get the string associated with a specific index value of the preset, seems like that string is just some gui feature and cant be found in the code itself.
its also strange that you cant find a custom preset in your code, what seems to show that presets do only "really" exist in gui
PS: it took like 15min to make the function cause there are really ALOT of keys, but its done now lol
@Mille25: Go
Algorithms like this is always faster than a big if-then-else chain! (@shakes his hand around like a mad proffessor@).
So you can use this way to identify numbers and letters and add all other controls manually.
Or you can do this:
This method is random-access. Basically can't get any faster.
Much better performance than a switch. At least how Blizzard implemented a switch. In real IDEs a switch would be just as fast.
And memory-wise it's the same too. Maybe even less memory-consuming.
PS: And yes, presets only exist in GUI.
However, Galaxy has a very similar kind of thing called typedef ( = type definition ) which allows up to map new names to existing types:
thanks for your reply.
however, where is the sense of this typedefs? why should i want to rename a variable type?
seems quite pointless to me :D
about performance, well, i dont think my switch statement will have real bad influence on map performance, so this is really not so important. there are much worse triggers. i just wanted the fastest and most confortable way for myself. another problem with doing this like you did is that your array must have the exact same keys for each index than the preset has, so you could easily save the wrong key in a specific index, as a very simple example if you say keys[0] = "B" and keys[1] = "A" you would get B if you press A key, it could get quite confusing for the special keys like control or alt. (@shakes his hand around like a mad proffessor@).
i think both methods have their own advantages, yours is faster while mine is more confortable.
anyway, thanks for you help :)
Why you would want typedefs are probably to make the code more readable.
A well example would be, say Dialogs and DialogControls. Both represent integers.
Say you make a custom function which is supposingly going to take a DialogControl as parameter, but when calling the function you make a mistake putting the Dialog id there instead. If the parameter name wouldn't have been very explanatory, using typedefs to explicitly ask for a type instead of just some integer, it could lead to less errors in the code.
Now, in galaxy maybe they didn't implement typedefs very well, because even though you create typedefs, they are still a representative of the base type.
So the compiler would accept a dialog typedef even though the function requires a dialogcontrol typedef, while in most other compilers, this wouldn't be valid to compile.
All keys in correct order:
http://pastebin.com/AN2t6dHi
Well, performance fanatic speaking out of me :3
Typedefs are like structs. Basically useless because you can do the same without them. Useful for organizing your code though, so it's easier to understand:
It helps you to not accidently enter wrong values and stuff.
Honestly it isn't really useful because we're missing so many things in Galaxy.
In real languages it makes more sense :p
Obvious what's easier to understand :)
PS: You can also make typedefs for structs, not only for primitives (I think).
But since you can't pass around structs it is of absolutely no fucking use.
Visual studio allows this, as both types boil down to being a int. So probably all/most C+ + compilers allow it. C# is more restrictive, I think.
Oh you're right. C# is the one I know being more strict. It is also strict in the same way regarding enums.
@s3rius: Go
This is off topic.. but s3rius, I swear you're like a guru to me. Every time you make a post, I learn new programming techniques and my coding style evolves >_> All hail to thee. One day, I aspire to be a programming god like you :D
@FuzzYD: Go
I wish I was a God.
But the more you think you know, the more you know that you didn't think of all the things you don't know.
If that makes sense :D
well, but normally the parameter name does that job, for exmaple "int DialogControl" would make clear that a dialog control is required, not a dialog.
its not a real difference if you got "DialogControl DC" instead of that imo.
same about sirius example... instead of calling the parameter "team t" i could also say "int team" what would be descriptive, too.
but i get your points, everyone should code like he wants to, but for me in galaxy this typedefs are not necessary.
Well, in that case it is a matter of preference I guess. But I think, just like in the trigger editor alot of types there are just native types in disguise (actorlink, etc) it could make it more understandable. While those disguised types there are not really needed, and does not really use typedefs (as the editor preprocessor is automatically correcting it) they would probably be alot more confusing to work with if presets of those fake types didn't exist.