| 09-25-2004, 05:05 AM | #1 |
uh, well ive been mostly been learning w/o a hitch, its not a very complex language, just gazilions of stinking functions, that i wish i could figure an easyer way to siphin through, anyway, i was wondering what makes it so that i need a call flag in front of a function sometimes? |
| 09-25-2004, 05:31 AM | #2 |
er, omg, i take it back, huge hitch here, another one of those "editor crashing" compiler errors... i cant believe HOW shitty the WE compiler is :/ function IsRoad takes nothing returns nothing if (GetUnitTypeId(GetEnumUnit()) == 'h00E') and (GetItemName(UnitItemInSlot(GetEnumUnit()) == "Connected Road") then return true endif return false endfunction function IsItaRoad takes nothing returns nothing //requires a global, boolean udg_Roads_OnRoad if (IsRoad()) then set udg_Roads_OnRoad = true endif endfunction function IsAttachedToRoad takes unit who, integer size returns boolean //size = 1 for a 4x4, 2 for a 8x8 // ====== // =1 22= // = 22= // ====== //requires two globals, udg_Roads_TemplateSize1;udg_Roads_TemplateSize2 local location unitspot = GetUnitLoc (who) set udg_Roads_OnRoad = false if (size==1) then call MoveRectTo(udg_Roads_TemplateSize1, GetLocationX(unitspot), GetLocationY(unitspot)) call ForGroupBJ(GetUnitsInRectAll( udg_Roads_TemplateSize1), function IsItaRoad) endif if (size==2) then call MoveRectTo(udg_Roads_TemplateSize2, GetLocationX(unitspot), GetLocationY(unitspot)) call ForGroupBJ(GetUnitsInRectAll( udg_Roads_TemplateSize2), function IsItaRoad) endif if (udg_Roads_OnRoad==true) then return true endif return false endfunction this crashes, when it gets to variables in the saving thing.... i have no idea why, looks good to me... (oh, btw this is supposed to go in the header... its going to be called often to verify that stuff is near a road...) |
| 09-25-2004, 07:36 AM | #3 |
You call a function when you don't care about its return value or it doesn't have one, I believe. Wouldn't IsRoad need to return a boolean? And I think you need another closing parenthesis after "Connected Road". |
| 09-25-2004, 08:31 AM | #4 |
And you are calling UnitItemInSlot with only one argument, it takes two. Code:
function UnitItemInSlot takes unit whichUnit, integer itemSlot returns item |
| 09-25-2004, 11:25 AM | #5 |
And please use the code tags. Then it is a lot easier to read. |
| 09-25-2004, 04:11 PM | #6 | |
Quote:
ok, are they just [ code ] [ /code ]? thanks everyone else.... i wish the f'n compiler could tell me this shiz, but instead it just crashes... (and the editor im using right now told me that it DID compile... stupid thing) |
| 09-25-2004, 04:38 PM | #7 | |
Jass is a very strict language--mainly because it's not a full language and the people using it are expected to know alot about what they're doing. Even a small syntax error can completely crash the editor and force you to start from the last spot you saved at--but saving is what causes the crashes. To be safe, you need to save after everything you do--but even this is not a sure-fire guarantee. Quote:
Call is used to call a function. It's not as easy to explain as it is to demonstrate. Code:
Call MyFunc() myVar = MyFunc() In the first case, I'm simply calling the function. Either I don't care about it's return value or it has none. In the second case, I want to assign the return value of the function to my variable. Code:
function IsRoad takes nothing returns [u]nothing[/u]
if (GetUnitTypeId(GetEnumUnit()) == 'h00E') and (GetItemName(UnitItemInSlot(GetEnumUnit()) == "Connected Road") then
return [u]true[/u]
endif
return [u]false[/u]
endfunctionThe parts I've underlined are conflicting. Your function is set to return nothing, but then you're trying to return boolean values. If you say that a function is going to return nothing then you can still use "return" but you can't put a value after it. To fix this function, use: Code:
function IsRoad takes nothing returns [b]boolean[/b]
if (GetUnitTypeId(GetEnumUnit()) == 'h00E') and (GetItemName(UnitItemInSlot(GetEnumUnit()) == "Connected Road") then
return true
endif
return false
endfunctionAnd as KaTTaNa said, your UnitItemInSlot is missing a paramater. If you're ever unsure about how to write a piece of JASS, then create a trigger that does what you want it to do. Convert it to JASS and check it out. |
| 09-25-2004, 05:03 PM | #8 |
The parser Blizzard uses is pretty crappy and buggy. You can use PJass instead to get better info but that means working outside of WE (or extracting the script to test it outside). On the other hand that has the advantage of being able to use a good text editor. |
| 09-26-2004, 02:02 AM | #9 |
One pretty good way to never lose work to crashing is by writing your JASS functions in a custom script trigger, now when it comes to test the function, do this: Disable the trigger. Save. (no chance of crash because WE doesn't parse disabled triggers) Enable the trigger. Save. If it crashes, just reload the map and you havn't lost anything. If it doesn't crash you can safely move the functions to the map header. The other thing I do is copy (ctrl-v) my new code right before saving, then if it crashes I just reload and paste it back in. |
