| 06-14-2004, 10:14 PM | #1 |
The editor GUI only allows doing math functions with integers and reals. I need to increment characters, which is possible in programming languages just by saying char a=a+1; and it increments the charatcer's ascii value. Warcraft 3 editor doesn't use characters, only strings. So I need some way to increment the last character of the string. like if I have a b there I need the function to change it to a c. Is this possible in jass? If so, could someone please help me out? I need this to link units to each other through unit-types which have names such as Custom_h00b and doing so through gui will create a really long an inefficient trigger. I don't usually use jass so I don't know much about it. Thanks. |
| 06-14-2004, 11:34 PM | #2 |
I am unsure yet what exactly you want to do but if you want to work with unit types then better use the type id since that is already an integer which is usually represented by the 4-letter-code. |
| 06-15-2004, 12:48 AM | #3 |
Can you not simply use arrays which have the unit IDs that AIAndy is speaking about? |
| 06-15-2004, 04:03 AM | #4 |
I'm not sure exactly how to access these unit IDs, and is it possible to influence the unit ID of a unit? For example, the reason I use unit-type is because they are assigned in the order that units are created, therefore as long as I create the upgrade unit next after the original unit, I can link the 2 together using unit-type. Also, for unit ID, is it possible to tell the editor to create a unit of type (Unit ID) like it's possible with unit-type? Also, AIAndy what I'm trying to do is to get a function where you give it a string signifying the unit-type of a unit like Custom_h00x, and it returns the string of the next unit, Custom_h00y (because y comes after x in alphabet and in ascii codes). |
| 06-15-2004, 05:35 AM | #5 |
I think I did it, here is the solution I came up with. Tell me if this is right, JASS isn't my specialty: function LetterUp takes string i returns string local integer k=0 local string s="ABCDEFGHIJKLMNOPQRSTUVWXYZ" loop set k = k + 1 exitwhen (i == SubStringBJ(s, k, k)) endloop set k = k + 1 return SubStringBJ(s, k, k) endfunction This function will work as long as i isn't Z, but I can avoid it by not creating units with Z values unless they're final upgrade. EDIT: HOLY CRAP, I just tried to experiment with the unitid thing, and it turns out it's also assigned in the same order the units are created. I'm actually beginning to think that unit-type is just GUI's ugly way of displaying unitid. Anyway, now I don't even have to write a function to convert anything. The code for upgrade now is so simple it makes me laugh: call IssueTrainOrderByIdBJ( udg_unit, GetUnitTypeId (udg_unit)+1 ) That's it, it works, I already tested it. Man, GUI cripples the abilities of triggers so much. I'll definatelly start learning JASS now. Speaking of which, is it possible to determine the unit's attack, range, attack speed, gold/lumber price in JASS? I know you can't edit it, but are there functions that return those values, because now I have to keep all that data in each unit's point value. Btw, thank you for helping me. |
| 06-15-2004, 12:37 PM | #6 |
No, you can't access any of those except the gold/lumber price, and that's using tricks (so no easy access there either). And it was this what AIAndy was trying to tell ya :). 'H000' isn't a string, it's a integer. That is, 256*256*256*256. So if you wanna increment the last char, you just add 1 to the integer. set MyInt = 'H000' + 1 - works. ~Cubasis |
| 06-15-2004, 04:23 PM | #7 |
There are natives to get the gold/lumber price in AI and I have written a simple dummy AI to serve these prices to triggers. It just requires this dummy AI to be run for a computer player or neutral hostile (strangely you can start AI scripts for neutral hostile but for no other neutral players). |
| 06-15-2004, 06:50 PM | #8 |
There is 1 problem I noticed though. Even though in hex values A comes after 9, in unitid that's not the case. When you do unitid+1, it doesn't change it to A if unitid is 9. And when you tell the game to display the integer value, it shows that there are 8 integers between 9 and A. Why is that? |
| 06-15-2004, 07:37 PM | #9 |
The reason for that is that that is not hex instead each of these is a character (probably ASCII). Maybe you should connect your units by using gamecache rather than the 4-letter-code. |
| 06-15-2004, 09:43 PM | #10 |
How do I work with gamecache? |
| 06-15-2004, 10:01 PM | #11 |
Using the return bug you can use it as a universal associative array. So you can store the second unit type under the first unit type and such things. Search for it and you should find some info about it. |
| 06-16-2004, 12:37 AM | #12 |
Well, I found quite a few posts refering to the return bug and game cache but none explaining it. I decided to go to the editor and look at game cache myself. It seems to me like just another array system that is more organized than normal arrays. And wouldn't I have to add units into those arrays first in order to use them? In that case, wouldn't setting up an array of integers at map initialization and filling it with UnitIDs be just as efficient as using game cache? And then to upgrade I could just move to the next array cell, although first I have to find which array cell the current unit is in, which might consume some time, but since the UnitIDs will be sorted I can use binary search with (O(log n)), or I could store the number of the array cell in unit's point value or something. How would game cache be more efficient? Unless it has a more efficient way of finding the array cell the unit is in. |
| 06-16-2004, 11:55 AM | #13 |
GameCache is accessed by string-keys, so you can structure/organize it very well. And it's rather implemented with Hash tables than linear searching at access, as test-results indicate that efficiency. So as you can access values in game-cache by strings, it imediately becomes very useful for alot of data structures. ~Cubasis |
