| 01-30-2009, 03:01 PM | #1 |
Okay, just wanted to ask if this script is useful. I see great use in it, and I use it much. So do you guys think so too, or is it just crap that I shouldn't submlibrary ColorHait? JASS:library ColorHandler //************************************************************** //* ColorHandler * //* Made by Vestras * //* * //* Usage * //* * //* Just do Color[whatPlayerId] and it will return the needed * //* color. * //* * //* Other possible stuff that can be done: * //* * //* If you want to change a standard color, just do * //* set Color[whatPlayerId] = myColor. You can only change * //* standard colors. * //* * //* That's it! Simple, eh? Now the only thing left is to use! * //* If you still don't quite get it, look at the example. * //************************************************************** struct Color static string array col[15] static method operator []= takes integer i, string s returns nothing set .col[i] = s endmethod static constant method operator [] takes integer i returns string return .col[i] endmethod private static method onInit takes nothing returns nothing set .col[0] = "|cffff0000" set .col[1] = "|cff0000ff" set .col[2] = "|cff93ffc9" set .col[3] = "|cff400080" set .col[4] = "|cffffff00" set .col[5] = "|cffff8000" set .col[6] = "|cff00c400" set .col[7] = "|cffff80c0" set .col[8] = "|cff808080" set .col[9] = "|cffc1c1ff" set .col[10] = "|cff004000" set .col[11] = "|cff5e5e2f" set .col[12] = "|cff000000" set .col[13] = "|cff000000" set .col[14] = "|cff000000" set .col[15] = "|cff000000" endmethod endstruct endlibrary JASS:library CHExample initializer Init requires ColorHandler private function Actions takes nothing returns nothing local integer j = 0 loop exitwhen j == 12 call DisplayTextToPlayer(Player(0), 0, 0, Color[j] + GetPlayerName(Player(0)) + "|r") set j = j + 1 endloop call DestroyTimer(GetExpiredTimer()) endfunction private function Init takes nothing returns nothing call TimerStart(CreateTimer(), 5, false, function Actions) endfunction endlibrary |
| 01-30-2009, 03:07 PM | #2 |
| 01-30-2009, 03:10 PM | #3 |
Isn't that just for hex colors? |
| 01-30-2009, 03:38 PM | #4 |
I think you want static stff vest: JASS:library ColorHandler //************************************************************** //* ColorHandler * //* Made by Vestras * //* * //* Usage * //* * //* Just do Color[whatPlayerId] and it will return the needed * //* color. * //* * //* Other possible stuff that can be done: * //* * //* If you want to change a standard color, just do * //* set Color[whatPlayerId] = myColor. You can only change * //* standard colors. * //* * //* That's it! Simple, eh? Now the only thing left is to use! * //* If you still don't quite get it, look at the example. * //************************************************************** function Color takes player p returns string return Color[GetPlayerId(p)] endfunction struct Color static string array col[12] static method operator []= takes integer i, string s returns nothing set .col[i] = s endmethod static method operator [] takes integer i returns string return .col[i] endmethod private static method onInit takes nothing returns nothing set .col[0] = "|cffff0000" set .col[1] = "|cff0000ff" set .col[2] = "|cff93ffc9" set .col[3] = "|cff400080" set .col[4] = "|cffffff00" set .col[5] = "|cffff8000" set .col[6] = "|cff00c400" set .col[7] = "|cffff80c0" set .col[8] = "|cff808080" set .col[9] = "|cffc1c1ff" set .col[10] = "|cff004000" set .col[11] = "|cff5e5e2f" set .col[12] = "|cff000000" set .col[13] = "|cff000000" set .col[14] = "|cff000000" set .col[15] = "|cff000000" endmethod endstruct endlibrary |
| 01-30-2009, 04:19 PM | #5 |
Erhm? What? I want you to use it the way you do now. Like call BJDebugMsg(Color[0] + "redlulzftw.|r")
Why would I want that instead of what I got now? EDIT: ah, I get it. So I don't have to declare a struct... I see... hmmz. |
| 01-30-2009, 04:19 PM | #6 |
I don't know. I'm sure there's enough evidence around here that shows that function calls are slower than array lookups... This library might as well be a global string array for the colors. It just doesn't seem useful to me since you're using a function to get a color from an array anyway where you can use the index that you would've anyway for just the array. Edit: I mean, you can clearly use whatever libraries you want to use for your maps =P. But this method is slower than an array lookup and you're using a function call to do that work for you. Calling Color(1) is the same result as Color[1] ... |
| 01-30-2009, 04:44 PM | #7 |
Yes what is the point of this exactly :o Anyway you could make the method operators constant to make it not have a function calll.. idono |
| 01-30-2009, 05:49 PM | #8 |
This method is IMO 'easier' to use and smoother, and since the speed reduction is so slight I'd rather want this method. I mean the Color[0] + "redlulzftw.|r". |
| 01-30-2009, 06:59 PM | #9 |
This is just an array obfuscated inside a struct wrapper. Graveyarded. Really. |
