| 02-28-2003, 08:45 PM | #16 |
So it ends the function, and stores the value or it prints it on the screen? Why not just use endfunction instead of using return, I still don't get it. |
| 02-28-2003, 11:19 PM | #17 |
Guest | Think of it this way. Lets say you use the "TellingTheTruth" function above like so... function example takes nothing returns nothing set udg_example = TellingTheTruth() endfunction Since "TellingTheTruth" returns false, udg_example = false. Make sense? |
| 03-01-2003, 12:07 AM | #18 |
Yeah I know that, I can understand basic JASS, I just don't understand the use of return, and maybe even IF's, like how using the method aurius (sp?) mentioned near the top is quicker and takes less typing. While I still try to learn JASS, could you explain in plain english how to check a variable array of 1-216 for 80 different things without it crashing, thats alot of computing it needs to do. Or if you know a better method..... |
| 03-01-2003, 12:33 AM | #19 |
Guest | The simplest way is to use a loop like we discussed above. Example: Code:
set udg_check[1] = "Militia"
set udg_unitType[1] = 'hmil'
set udg_check[2] = "Rifleman"
set udg_unitType[2] = 'hrif'
set udg_check[3] = "Patrol"
set udg_unitType[3] = 'hmpr'
...
function GetUnitType takes string whatUnit returns integer
local integer thisUnit
local i = 0
loop
exitwhen i > 3
if whatUnit == udg_check[i] then
set thisUnit = udg_unitType[i]
set i = 4
else
set i = i + 1
endif
endloop
return thisUnit
endfunctionOK. The first part would go into the initialization function of the trigger (the last one). Then whenever you call the function: GetUnitType(whatUnit) you will return the unit type. For example: call GetUnitType("Militia") Would sorts through the udg_check array until "i" is equal to the array index that matches the string "Militia". In this case, it is 1. The value of udg_unitType[i] is then returned. That's basically what you are trying to do when you are using a loop to sort throught arrays. In your case, you are trying to detect 80 different things. So you need to have 80 different array variables defined. ::EDIT:: By the way, it may seem confusing but unit types are stored as integers for whatever reason. Oddly, the form you use to store it resembles nothing like an integer (example: 'hmil' is considered an integer). I always thought it was wierd they didn't define unit type as it's own type and make it an extension of string...but who am I to argue with Blizzard:0 |
| 03-01-2003, 12:41 AM | #20 |
*smacks head on keyboard* I feel like such an idiot.... But thanks that helps, one more thing, since I'm going through 80 different "checks" I would make "exitwhen i > 3" I'd make the 3 an 80 right? I'm sorry about the difficulty I'm having understanding this, JASS is new to me. Lately I've been doing regular scripting in the GUI and minor JASS (copying things under IF's etc.), terraining and everything else (besides modelling lol). Thanks for sticking around with the problems. I though I might aswell learn JASS so I don't have to get other people to do it for me, and have troubles explaining what I want. *points to his question above* Don't forget about answering that ;) |
| 03-01-2003, 12:50 AM | #21 |
Guest | For an even crazier example of the above...look at my GetUnitInteger function (see signature). It assigns an integer that can be stored in an array to reference a specific unit. For example, let's say you want to keep track of the # of kills a specific UNIT has had. Well, for a PLAYER, this would be easy. You would simply create an array where the index was the player number. But for a specific unit... WC3 has no built-in way to have an integer for a unit that can be used in array like that. But by storing the unit information in a sequential array that adds units on the fly, I can create a loop that looks through that array to find that unit and return the integer (which is just the "i" in the above example) for that unit. This integer is unique and specific to that unit and I can use it in ANY array variable I want to pull up or store specific information about that unit. |
| 03-01-2003, 12:51 AM | #22 |
Guest | Yes. You would use 80 instead since you have 80 different instances. |
| 03-01-2003, 02:10 PM | #23 | |
Quote:
The code I posted several posts back should handle what you are needing. I'm posting it again in case you missed it. Code:
function Convert_Actions takes nothing returns nothing
local integer x = 0 // position in udg_String array
local integer y = 1 // substring position in udg_replaceables
// and position for udg_newStr array
local integer p = 0 // associate player number
loop // loop for every player
exitwhen p > 11
loop // loop through udg_String
exitwhen x > 215
loop // loop through udg_replaceables
exitwhen y > 80
if ( udg_String[x] == SubStringBJ(udg_replaceables, y, y) ) then
set udg_String[x] == udg_newStr[y]
exitwhen true // if we match, exit the loop
endif
set y = y + 1
endloop
set x = x + 12
endloop
set p = p + 1
endloop
endfunctionBased on what I understand about your problem, is that you want to replace letters, numbers, symbols, etc... with a number. By setting the replaceables string to all of the possibilities, and initializing the newStr array with what you want to replace, the 3 loop scenario above will handle this. By the way, newStr is a string array since you will be replacing items in your String array. You can, however, easily use the S2I() function to convert the strings into the number that you need after the array has been parsed. |
| 03-01-2003, 02:42 PM | #24 | |
Quote:
If you are not returning a value, for the most part you never need to use the return statement. There are instances where using return is usefull for exiting a trigger early to prevent remaining actions from being run. Note that Skip Remaining Actions in the editor GUI is nothing more than the return statement. |
| 03-01-2003, 08:43 PM | #25 |
... my code as of right now: Code:
function Trig_Converting_Actions takes nothing returns nothing
local integer x
local integer y
set x = GetConvertedPlayerId(udg_TriggeringPlayer)
set y = 0
set udg_Convert[GetConvertedPlayerId(udg_TriggeringPlayer)] = true
loop
exitwhen x > 215
loop
exitwhen y > 79
if ( udg_Password[x] == udg_Converting[y] ) then
set udg_PasswordCon[x] = udg_Converting2[y]
endif
set y = y + 1
call TriggerSleepAction( 0.01 )
endloop
set x = x + 12
call TriggerSleepAction( 0.01 )
endloop
set udg_Convert[GetConvertedPlayerId(udg_TriggeringPlayer)] = false
call ConditionalTriggerExecute( gg_trg_Untitled_Trigger_001 )
endfunction
//===========================================================================
function InitTrig_Converting takes nothing returns nothing
set gg_trg_Converting = CreateTrigger( )
call TriggerAddAction( gg_trg_Converting, function Trig_Converting_Actions )
endfunctionPassword[#] is what it is taking the characters from, already defined. PasswordCon is another variable I made so when I change the value from A to 10 it will remain A in the password string. Converting is what it would match to, A=A, b=b etc. Converting2 is the values, A=10, F=15 etc. When I call the Untitled Trigger (which prints the value of all the modified arrays) it prints (null). Is there something wrong with the Set Variable command I have there? It doesn't seem to want to change it. Is the code not working the way it should? Because it has to do this many times, each Password[X] is a different number, but it could be the same as Converting[Y], and if it is, it should change the value of PasswordCon[X] to Converting2[Y]. Please help. |
| 03-01-2003, 09:05 PM | #26 |
The only problem I can see is udg_TriggeringPlayer is not set anywhere. Are you sure you didn't mean to do... Set x = GetConvertedPlayerId(GetTriggerPlayer()) |
| 03-01-2003, 09:15 PM | #27 |
No triggering player variable is a triggering player, its set in the trigger before this one, so I have somethign to refer to in this one. |
| 03-01-2003, 09:42 PM | #28 | |
Guest | Quote:
hey thought this might not fixed ur problem coz I don't really understand what u want to do but juz wanna point out that, your inner loop with the statement "exitwhen y > 79" will only run for the first pass, meaning after the loop is done, and x get updated, the innerloop will never be run again coz y is still > 79. |
| 03-01-2003, 09:57 PM | #29 |
Y starts at 0, then it gets to 1, then 2 then 3 and so on. |
| 03-01-2003, 09:57 PM | #30 |
Excellent find Garbot, even I missed that. :) Need to set y = 0 after the set x = x + 12. |
