• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Syntax error problem?

Status
Not open for further replies.
Level 3
Joined
Oct 8, 2007
Messages
41
I am quite new to Jass so forgive me if i am asking a stupid question, I have a problem that i just cant understand

for some reason Jass Helper sasy this line has a "Syntax Error":
JASS:
function LandRandom_Conditions takes nothing returns boolean

this is like the full of that part, or should i post the entire trigger here?(i thought that might not be neccessary since it is only that line that has the error.
JASS:
function LandRandom_Conditions takes nothing returns boolean
 return GetUnitTypeId(GetTriggerUnit) == 'h000'
endfunction
 
Level 11
Joined
Feb 18, 2004
Messages
394
post the complete trigger. Syntax checkers commonly error on the line after, or even a while after the actual error. That function parses fine by itself, so the problem is likely above it... post the whole trigger anyway.

edit: Ok, im wrong. Thus why syntax checkers are bad, and actually knowing shit and checking code is good...
return GetUnitTypeId(GetTriggerUnit) == 'h000'
GetTriggeringUnit()
 
Last edited:
Level 3
Joined
Oct 8, 2007
Messages
41
Added the () ,but the error still appears:
JASS:
function LandRandom_Conditions takes nothing returns boolean
 return GetUnitTypeId(GetTriggerUnit()) == 'h000'
endfunction

The full code is:
JASS:
function LandRandom_izer takes player p, integer w, integer u, integer b, integer r, integer g, integer slandn, unit sland, unit sland2, unit sland3, unit sland4, unit sland5 returns nothing
 local integer randomn = GetRandomInt(1,100)
 local integer srandomn = GetRandomInt(1,slandn)
 local location loc = GetUnitLoc(GetConstructedStructure())
 if 1 <= randomn and randomn <= w then
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(p, 'h001', loc, 0.0)
 elseif (w+1) <= randomn and randomn <= (w+u) then
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(p, 'h002', loc, 0.0)
 elseif (w+u+1) <= randomn and randomn <= (w+u+b) then
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(p, 'h003', loc, 0.0)
 elseif (w+u+b+1) <= randomn and randomn <= (w+u+b+r) then
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(p, 'h004', loc, 0.0)
 elseif (w+u+b+r+1) <= randomn and randomn <= (w+u+b+r+g) then
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(p, 'h005', loc, 0.0)
 else
  if srandomn == slandn then
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(p, sland, loc, 0.0)
  elseif srandomn == (slandn-1) then
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(p, sland2, loc, 0.0)
  elseif srandomn == (slandn-2) then
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(p, sland3, loc, 0.0)
  elseif srandomn == (sland-3) then
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(p, sland4, loc, 0.0)
  elseif srandomn == (sland-4) then
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(p, sland5, loc, 0.0)
  endif
 endif

function LandRandom_Conditions takes nothing returns boolean
 return GetUnitTypeId(GetTriggerUnit()) == 'h000'
endfunction

function Trig_LandRandom_Actions takes nothing returns nothing
//!textmacro playerheroif takes PLAYER, PLAYERDATAVARIABLE
 if GetOwningPlayer(GetConstructedStructure()) == $PLAYER$ then
  call LandRandom_izer($PLAYERDATAVARIABLE$.p, $PLAYERDATAVARIABLE$.w, $PLAYERDATAVARIABLE$.u, $PLAYERDATAVARIABLE$.b, $PLAYERDATAVARIABLE$.r, $PLAYERDATAVARIABLE$.g, $PLAYERDATAVARIABLE$.slandn, $PLAYERDATAVARIABLE$.sland, $PLAYERDATAVARIABLE$.sland2, $PLAYERDATAVARIABLE$.sland3, $PLAYERDATAVARIABLE$.sland4, $PLAYERDATAVARIABLE$.sland5)
 endif
//!endtextmacro

//!runtextmacro playerheroif("Player(0)","udg_player0")
//!runtextmacro playerheroif("Player(1)","udg_player1")
//!runtextmacro playerheroif("Player(2)","udg_player2")
//!runtextmacro playerheroif("Player(3)","udg_player3")
//!runtextmacro playerheroif("Player(4)","udg_player4")
//!runtextmacro playerheroif("Player(5)","udg_player5")
//!runtextmacro playerheroif("Player(6)","udg_player6")
//!runtextmacro playerheroif("Player(7)","udg_player7")
//!runtextmacro playerheroif("Player(8)","udg_player8")
endfunction

//===========================================================================
function InitTrig_LandRandom takes nothing returns nothing
    set gg_trg_LandRandom = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg/-trg_LandRandom, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH)
    call TriggerAddCondition(gg_trg_LandRandom, Condition(function LandRandom_Conditions))
    call TriggerAddAction( gg_trg_LandRandom, function Trig_LandRandom_Actions )
endfunction
 
Level 11
Joined
Feb 18, 2004
Messages
394
That is the most fucked up bit of code i have seen in a long time.

#1: If a function is taking that many arguments, you are doing something wrong. Very wrong.

#2:
JASS:
call TriggerRegisterAnyUnitEventBJ(gg/-trg_LandRandom, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH)
... gg/-trg_LandRandom wtf?

#3:
JASS:
//!textmacro playerheroif takes PLAYER, PLAYERDATAVARIABLE
 if GetOwningPlayer(GetConstructedStructure()) == $PLAYER$ then
  call LandRandom_izer($PLAYERDATAVARIABLE$.p, $PLAYERDATAVARIABLE$.w, $PLAYERDATAVARIABLE$.u, $PLAYERDATAVARIABLE$.b, $PLAYERDATAVARIABLE$.r, $PLAYERDATAVARIABLE$.g, $PLAYERDATAVARIABLE$.slandn, $PLAYERDATAVARIABLE$.sland, $PLAYERDATAVARIABLE$.sland2, $PLAYERDATAVARIABLE$.sland3, $PLAYERDATAVARIABLE$.sland4, $PLAYERDATAVARIABLE$.sland5)
 endif
//!endtextmacro
Again, wtf? why aren't you using an array and loops? and are the udg_player# variables of a struct-type value? if not, what the fuck is with the dots? i would call that text macro abuse, but its just stupidity.

#4: function LandRandom_izer is missing an endfunction

#5: i have NO IDEA what the FUCK you are even trying to do in this code. The variable names explain nothing, there are no comments, is filled to the breaking point with syntax errors... you're misusing text macros (namely because they are not the solution to your problem =.=)...

#6: you're using the udg_ prefix when you are using JASSHelper for vJASS? wtf?

#7: call CreateUnitAtLoc(p, sland, loc, 0.0) you're passing a unit type variable to a function which takes an integer? wtf? and you do it 4 more times!

#8: elseif srandomn == (sland-3) then ...


... I'm sorry, the only thing i can recomend is the following:
  1. Read a JASS Tutorial or Two
  2. Learn How to Code
  3. Rewrite this Whole Script
 
Level 3
Joined
Oct 8, 2007
Messages
41
I am sorry for the big mess up probably i should have posted EVERYTHING that was involved with the trigger, my bad. And since then , i have refined and fixed some(not so "some") of the errors.

this is in a first trigger to set things up and all:
JASS:
struct playerdata// struct to keep the player data which would be needed later
 player p//not implamented yet
 unit hero//not implamented yet
 integer w//Basically these w,u,b,r,g numbers are used 
 integer u//to set different 
 integer b//poportions of randomness
 integer r//if the player chooses
 integer g//different heroes
 integer slandn//So i can adjust the amount of special building a hero would have
 integer sland// the integer of the special building of hero
 integer sland2//so is sland2 to sland5
 integer sland3
 integer sland4
 integer sland5
 
  method inputherodata takes integer w, integer u, integer b, integer r, integer g, integer slandn, integer sland, integer sland2, integer sland3, integer sland4, integer sland5 returns nothing
   set this.w = w
   set this.u = u
   set this.b = b
   set this.r = r
   set this.g = g
   set this.slandn = slandn
   set this.sland = sland
   set this.sland2 = sland2
   set this.sland3 = sland3
   set this.sland4 = sland4
   set this.sland5 = sland5
 endmethod//this method is just because i am lazy to type "set" this and that later in the coding.
endstruct

globals //struct globals for players since they are going to be acessed not just locally
 playerdata udg_player0
 playerdata udg_player1
 playerdata udg_player2
 playerdata udg_player3
 playerdata udg_player4
 playerdata udg_player5
 playerdata udg_player6
 playerdata udg_player7
 playerdata udg_player8
endglobals

function Trig_HeroType_Actions takes nothing returns nothing
 set udg_player0 = playerdata.create()//have to create it here, not gonna use it before this anyway
 set udg_player1 = playerdata.create()
 set udg_player2 = playerdata.create()
 set udg_player3 = playerdata.create()
 set udg_player4 = playerdata.create()
 set udg_player5 = playerdata.create()
 set udg_player6 = playerdata.create()
 set udg_player7 = playerdata.create()
 set udg_player8 = playerdata.create()
 if GetOwningPlayer(GetSoldUnit()) == Player(0) then// this entire thing only works for player(0) for 
  set udg_player0.hero = GetSoldUnit()              //testing.
  set udg_player0.p = Player(0)
  if GetUnitTypeId(GetSoldUnit()) == 'N002' then//Sets things up for later use 
   call udg_player0.inputherodata(10,10,0,60,0,2,'h006','h007',0,0,0)//depending on the hero bought
   //too lazy to type, so used method
  elseif GetUnitTypeId(GetSoldUnit()) == 'N006' then
   call udg_player0.inputherodata(0,0,20,0,70,3,'h006','h007','h008',0,0)
   //too lazy to type, so used method
  endif
 endif
endfunction

//===========================================================================
function InitTrig_HeroType takes nothing returns nothing
    set gg_trg_HeroType = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_HeroType,EVENT_PLAYER_UNIT_SELL)
    call TriggerAddAction( gg_trg_HeroType, function Trig_HeroType_Actions )
endfunction

The second part is (the one i posted earlier):
JASS:
function LandRandom_izer takes integer w, integer u, integer b, integer r, integer g, integer slandn, integer sland, integer sland2, integer sland3, integer sland4, integer sland5 returns nothing
 local integer randomn = GetRandomInt(1,100)//gets the random number
 local integer srandomn = GetRandomInt(1,slandn)//another random
 local location loc = GetUnitLoc(GetConstructedStructure())//where to replace
 if 1 <= randomn and randomn <= w then//This makes the ratio of 
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h001', loc, 0.0)
 elseif (w+1) <= randomn and randomn <= (w+u) then//getting these if,elseif,else adjustable
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h002', loc, 0.0)
 elseif (w+u+1) <= randomn and randomn <= (w+u+b) then
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h003', loc, 0.0)
 elseif (w+u+b+1) <= randomn and randomn <= (w+u+b+r) then
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h004', loc, 0.0)
 elseif (w+u+b+r+1) <= randomn and randomn <= (w+u+b+r+g) then
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h005', loc, 0.0)
 else//If the number is none of the above
  if srandomn == slandn then//Just deciding what special building
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), sland, loc, 0.0)
  elseif srandomn == (slandn-1) then//Since "slandn" is a unknown number in the random,
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), sland2, loc, 0.0)
  elseif srandomn == (slandn-2) then//this way is used
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), sland3, loc, 0.0)
  elseif srandomn == (sland-3) then
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), sland4, loc, 0.0)
  elseif srandomn == (sland-4) then
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), sland5, loc, 0.0)
  endif
 endif
 set loc = null
endfunction

function LandRandom_Conditions takes nothing returns boolean
 return GetUnitTypeId(GetTriggerUnit()) == 'h000'//this is like the dummy building, once complete will be replaced with random building
endfunction

function Trig_LandRandom_Actions takes nothing returns nothing
 if GetOwningPlayer(GetConstructedStructure()) == Player(0) then
  call LandRandom_izer(udg_player0.w, udg_player0.u, udg_player0.b, udg_player0.r, udg_player0.g, udg_player0.slandn, udg_player0.sland, udg_player0.sland2, udg_player0.sland3, udg_player0.sland4, udg_player0.sland5)
 endif//this only works for player(0) for testing

endfunction

//===========================================================================
function InitTrig_LandRandom takes nothing returns nothing
    set gg_trg_LandRandom = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_LandRandom, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH)
    call TriggerAddCondition(gg_trg_LandRandom, Condition(function LandRandom_Conditions))
    call TriggerAddAction( gg_trg_LandRandom, function Trig_LandRandom_Actions )
endfunction

And to reply to Earth-Fury's post:
That is the most fucked up bit of code i have seen in a long time.
haha i know, i know i messed ALOT up.

#1: If a function is taking that many arguments, you are doing something wrong. Very wrong.

I dont understand this part, please explain.

#2:
JASS:
call TriggerRegisterAnyUnitEventBJ(gg/-trg_LandRandom, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH)
... gg/-trg_LandRandom wtf?

Woops typo didnt see that XD.

#3:
JASS:
//!textmacro playerheroif takes PLAYER, PLAYERDATAVARIABLE
 if GetOwningPlayer(GetConstructedStructure()) == $PLAYER$ then
  call LandRandom_izer($PLAYERDATAVARIABLE$.p, $PLAYERDATAVARIABLE$.w, $PLAYERDATAVARIABLE$.u, $PLAYERDATAVARIABLE$.b, $PLAYERDATAVARIABLE$.r, $PLAYERDATAVARIABLE$.g, $PLAYERDATAVARIABLE$.slandn, $PLAYERDATAVARIABLE$.sland, $PLAYERDATAVARIABLE$.sland2, $PLAYERDATAVARIABLE$.sland3, $PLAYERDATAVARIABLE$.sland4, $PLAYERDATAVARIABLE$.sland5)
 endif
//!endtextmacro
Again, wtf? why aren't you using an array and loops? and are the udg_player# variables of a struct-type value? if not, what the fuck is with the dots? i would call that text macro abuse, but its just stupidity.

yup udg_player# is a struct(check the top codes in this post) ,and i given up on using textmacro

#4: function LandRandom_izer is missing an endfunction

yeah that was the culprit in the original post i guess

#5: i have NO IDEA what the FUCK you are even trying to do in this code. The variable names explain nothing, there are no comments, is filled to the breaking point with syntax errors... you're misusing text macros (namely because they are not the solution to your problem =.=)...

Well my newly added coments should help? no? well its basically a code that "builds" a random building, but the ratio of randomness can be adjusted according to the hero the player is using.

#6: you're using the udg_ prefix when you are using JASSHelper for vJASS? wtf?

ermm, i dont really understand what you mean, but i just name it udg_wateva cause i want to recognise it as a global and didnt know what else to name it

#7: call CreateUnitAtLoc(p, sland, loc, 0.0) you're passing a unit type variable to a function which takes an integer? wtf? and you do it 4 more times!

haha well my mistake, i am not very experienced(as you can see) and i dont really know what that function wants.(fixed it by the way)

#8: elseif srandomn == (sland-3) then ...

i dont really know what you are asking or saying again this time.

  1. Read a JASS Tutorial or Two

  1. of course i read tutorials, or else i wouldnt even know what in the world is vJASS or what a local variable is.Heck, i wouldnt even know how to write what you call :
    "...the most fucked up bit of code i have seen in a long time."

    [*]Learn How to Code
    Trying to

    [*]Rewrite this Whole Script
Did that.
 
Level 11
Joined
Feb 18, 2004
Messages
394
JASS:
struct playerdata// struct to keep the player data which would be needed later
 player p//not implamented yet
 unit hero//not implamented yet
 integer w//Basically these w,u,b,r,g numbers are used 
 integer u//to set different 
 integer b//poportions of randomness
 integer r//if the player chooses
 integer g//different heroes
 integer slandn//So i can adjust the amount of special building a hero would have
 integer sland// the integer of the special building of hero
 integer sland2//so is sland2 to sland5
 integer sland3
 integer sland4
 integer sland5
 
  method inputherodata takes integer w, integer u, integer b, integer r, integer g, integer slandn, integer sland, integer sland2, integer sland3, integer sland4, integer sland5 returns nothing
   set this.w = w
   set this.u = u
   set this.b = b
   set this.r = r
   set this.g = g
   set this.slandn = slandn
   set this.sland = sland
   set this.sland2 = sland2
   set this.sland3 = sland3
   set this.sland4 = sland4
   set this.sland5 = sland5
 endmethod//this method is just because i am lazy to type "set" this and that later in the coding.
endstruct
This... makes little sense.
  1. Struct names usually have the naming convention of "EveryFirstLetterInAWordIsACapitol"
  2. JASS:
     integer w//Basically these w,u,b,r,g numbers are used 
     integer u//to set different 
     integer b//poportions of randomness
     integer r//if the player chooses
     integer g//different heroes
    Why are you not using an array? (arrays as struct members, unlike normal arrays, have a static length. check the JASSHelper manual for more information)
  3. JASS:
     integer slandn//So i can adjust the amount of special building a hero would have
     integer sland// the integer of the special building of hero
     integer sland2//so is sland2 to sland5
     integer sland3
     integer sland4
     integer sland5
    Again, why are you not using an array? And the common naming convention i see for arrays is: integer sLandCount and integer array sLands
  4. If a function takes more than 4 arguments (arguments are what you pass to a function as in: call MyFunc("argument 1", 2, 3) ) then you need to rethink your code. functions should only take a few arguments to keep code simple and concise. Methods are functions in this context.

JASS:
globals //struct globals for players since they are going to be acessed not just locally
 playerdata udg_player0
 playerdata udg_player1
 playerdata udg_player2
 playerdata udg_player3
 playerdata udg_player4
 playerdata udg_player5
 playerdata udg_player6
 playerdata udg_player7
 playerdata udg_player8
endglobals
Do you even know what an array is?! If you don't, i suggest you learn, then come back to this code :) anyway, use an array here. also, get rid of the udg_ prefix... it serves no purpose, as you can know what is a global by a naming convention like:
  • All global variables start in a capital letter, and each first letter of each word is a capital, ala "ThisIsAGlobal"
  • All local variables start in a lower case letter, and each first letter of each word (other than the first) is a capital, ala "thisIsALocal".

JASS:
globals
    playerdata array PlayersData
endglobals

JASS:
function Trig_HeroType_Actions takes nothing returns nothing
 set udg_player0 = playerdata.create()//have to create it here, not gonna use it before this anyway
 set udg_player1 = playerdata.create()
 set udg_player2 = playerdata.create()
 set udg_player3 = playerdata.create()
 set udg_player4 = playerdata.create()
 set udg_player5 = playerdata.create()
 set udg_player6 = playerdata.create()
 set udg_player7 = playerdata.create()
 set udg_player8 = playerdata.create()
 if GetOwningPlayer(GetSoldUnit()) == Player(0) then// this entire thing only works for player(0) for 
  set udg_player0.hero = GetSoldUnit()              //testing.
  set udg_player0.p = Player(0)
  if GetUnitTypeId(GetSoldUnit()) == 'N002' then//Sets things up for later use 
   call udg_player0.inputherodata(10,10,0,60,0,2,'h006','h007',0,0,0)//depending on the hero bought
   //too lazy to type, so used method
  elseif GetUnitTypeId(GetSoldUnit()) == 'N006' then
   call udg_player0.inputherodata(0,0,20,0,70,3,'h006','h007','h008',0,0)
   //too lazy to type, so used method
  endif
 endif
endfunction

ignoring the fact that you're mixing struct declarations with some random trigger for now, you're doing one major thing wrong: you're initializing the struct variables for every player every time one buys a unit.

so lets split all this up. Create 2 "triggers" in the world editor, name one "PlayerData" and the other whatever. in "PlayerData", use a library with an initializer as such:
JASS:
library PlayerData initializer init

struct playerdata// struct to keep the player data which would be needed later
 player p//not implamented yet
 unit hero//not implamented yet
 integer w//Basically these w,u,b,r,g numbers are used 
 integer u//to set different 
 integer b//poportions of randomness
 integer r//if the player chooses
 integer g//different heroes
 integer slandn//So i can adjust the amount of special building a hero would have
 integer sland// the integer of the special building of hero
 integer sland2//so is sland2 to sland5
 integer sland3
 integer sland4
 integer sland5
 
  method inputherodata takes integer w, integer u, integer b, integer r, integer g, integer slandn, integer sland, integer sland2, integer sland3, integer sland4, integer sland5 returns nothing
   set this.w = w
   set this.u = u
   set this.b = b
   set this.r = r
   set this.g = g
   set this.slandn = slandn
   set this.sland = sland
   set this.sland2 = sland2
   set this.sland3 = sland3
   set this.sland4 = sland4
   set this.sland5 = sland5
 endmethod//this method is just because i am lazy to type "set" this and that later in the coding.
endstruct

globals //struct globals for players since they are going to be acessed not just locally
 playerdata udg_player0
 playerdata udg_player1
 playerdata udg_player2
 playerdata udg_player3
 playerdata udg_player4
 playerdata udg_player5
 playerdata udg_player6
 playerdata udg_player7
 playerdata udg_player8
endglobals

private function init takes nothing returns nothing
 set udg_player0 = playerdata.create()
 set udg_player1 = playerdata.create()
 set udg_player2 = playerdata.create()
 set udg_player3 = playerdata.create()
 set udg_player4 = playerdata.create()
 set udg_player5 = playerdata.create()
 set udg_player6 = playerdata.create()
 set udg_player7 = playerdata.create()
 set udg_player8 = playerdata.create()
endfunction
endlibrary

init will then be called before all InitTrig_Whatever() functions. any functions you stick in a library will also be moved to the top of the map script, allowing you to use them anywhere. (check the JASSHelper manual for more information about librarys)

if you turn sane and use an array, init would look like:
JASS:
private function init takes nothing returns nothing
    local integer i = 0
    loop
        exitwhen i > 11

        set PlayersData[i] = playerdata.create()
        set PlayersData[i].p = Player(i)

        set i = i + 1
    endloop
endfunction

In the other trigger i told you to create, you would put the rest of that crap in to it. Except you would want it coded sanely, something like:
JASS:
function Trig_HeroType_Actions takes nothing returns nothing
    local player p = GetOwningPlayer(GetSoldUnit())
    
    // using an array where you where using a bunch of globals...
    set PlayersData[GetPlayerId(p)].hero = GetSoldUnit()
    if GetUnitTypeId(GetSoldUnit()) == 'N002' then//Sets things up for later use 
        // Don't use that lame method... just write out all the needed set statements and CnP... or use a loop of some kind here
    elseif GetUnitTypeId(GetSoldUnit()) == 'N006' then
        
    endif
endfunction

//===========================================================================
function InitTrig_HeroType takes nothing returns nothing
    set gg_trg_HeroType = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_HeroType,EVENT_PLAYER_UNIT_SELL)
    call TriggerAddAction( gg_trg_HeroType, function Trig_HeroType_Actions )
endfunction



elseif srandomn == (sland-3) then sland is of the type unit... which means this is beyond wrong. (units are not numbers... and using rawcodes as numbers is a bad idea. rawcodes being 'RawC'

i still have no fucking idea what you're trying to achive in the second trigger, and im too lazy to look over it right now...
 
Level 3
Joined
Oct 8, 2007
Messages
41
This is my 2nd Refined Coding:
The initializer, global, structs trigger:
JASS:
library PlayerData initializer init
struct PlayerData// struct to keep the player data which would be needed later 
 player p
 unit hero//not implamented yet
 integer w//Basically these w,u,b,r,g numbers are used 
 integer u//to set different 
 integer b//poportions of randomness
 integer r//if the player chooses
 integer g//different heroes
 integer sLandCount//So i can adjust the amount of special building a hero would have
 integer sLand// the integer of the special building of hero
 integer sLand2//so is sland2 to sland5
 integer sLand3
 integer sLand4
 integer sLand5
endstruct

globals //struct globals for players since they are going to be acessed not just locally
 PlayerData array PlayerDataArray
endglobals

function init takes nothing returns nothing//loop to create each of the structs
 local integer i = 0
 loop
   exitwhen i>11
   set PlayerDataArray[i] = PlayerData.create()
   set PlayerDataArray[i].p = Player(i)
   set i = i+1
 endloop
endfunction

endlibrary
//===========================================================================
function InitTrig_PlayerData takes nothing returns nothing
    set gg_trg_PlayerData = CreateTrigger(  )
    call TriggerAddAction( gg_trg_PlayerData, function init )
endfunction

You might noticed i didnt used arrays for the w,u,b,r,g and the sLand stuff, i will explain it in the reply to Earth_Fury's post further down.

The second part(which is now split from the first one):
JASS:
function Trig_HeroType_Actions takes nothing returns nothing
 local integer playerId = GetPlayerId(GetOwningPlayer(GetSoldUnit()))//so it easier to read and more concise
 set PlayerDataArray[playerId].hero = GetSoldUnit()
  if GetUnitTypeId(GetSoldUnit()) == 'N002' then//Sets things up for later use 
   set PlayerDataArray[playerId].w = 10//dumped the method thing
   set PlayerDataArray[playerId].u = 10
   set PlayerDataArray[playerId].b = 0
   set PlayerDataArray[playerId].r = 70
   set PlayerDataArray[playerId].g = 0
   set PlayerDataArray[playerId].sLandCount = 2
   set PlayerDataArray[playerId].sLand = 'h006'
   set PlayerDataArray[playerId].sLand2 = 'h007'
   set PlayerDataArray[playerId].sLand3 = 0
   set PlayerDataArray[playerId].sLand4 = 0
   set PlayerDataArray[playerId].sLand5 = 0
  elseif GetUnitTypeId(GetSoldUnit()) == 'N006' then
   set PlayerDataArray[playerId].w = 0
   set PlayerDataArray[playerId].u = 0
   set PlayerDataArray[playerId].b = 20
   set PlayerDataArray[playerId].r = 0
   set PlayerDataArray[playerId].g = 70
   set PlayerDataArray[playerId].sLandCount = 3
   set PlayerDataArray[playerId].sLand = 'h006'
   set PlayerDataArray[playerId].sLand2 = 'h007'
   set PlayerDataArray[playerId].sLand3 = 'h008'
   set PlayerDataArray[playerId].sLand4 = 0
   set PlayerDataArray[playerId].sLand5 = 0
  endif
endfunction

//===========================================================================
function InitTrig_HeroType takes nothing returns nothing
    set gg_trg_HeroType = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_HeroType,EVENT_PLAYER_UNIT_SELL)
    call TriggerAddAction( gg_trg_HeroType, function Trig_HeroType_Actions )
endfunction

The third part is to replace the built dummy building with a random building, the complicated stuff is so that it still works the same way although the values of some of the variables are changed:
JASS:
function LandRandom_izer takes nothing returns nothing
 local integer randomn = GetRandomInt(1,100)//gets the random number
 local location loc = GetUnitLoc(GetConstructedStructure())//where to replace
 local integer playerId = GetPlayerId(GetOwningPlayer(GetConstructedStructure()))
 local integer w = PlayerDataArray[playerId].w//These are to make,
 local integer u = PlayerDataArray[playerId].u//the code more,
 local integer b = PlayerDataArray[playerId].b//concise and,
 local integer r = PlayerDataArray[playerId].r//easier to read,
 local integer g = PlayerDataArray[playerId].g//later on
 local integer sLandCount = PlayerDataArray[playerId].sLandCount//so is all
 local integer sLand = PlayerDataArray[playerId].sLand//these,
 local integer sLand2 = PlayerDataArray[playerId].sLand2//and these.
 local integer sLand3 = PlayerDataArray[playerId].sLand3
 local integer sLand4 = PlayerDataArray[playerId].sLand4
 local integer sLand5 = PlayerDataArray[playerId].sLand5
 local integer srandomn = GetRandomInt(1,sLandCount)//another random
 if 1 <= randomn and randomn <= w then//This makes the ratio of 
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h001', loc, 0.0)
 elseif (w+1) <= randomn and randomn <= (w+u) then//getting these if,elseif,else adjustable
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h002', loc, 0.0)
 elseif (w+u+1) <= randomn and randomn <= (w+u+b) then
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h003', loc, 0.0)
 elseif (w+u+b+1) <= randomn and randomn <= (w+u+b+r) then
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h004', loc, 0.0)
 elseif (w+u+b+r+1) <= randomn and randomn <= (w+u+b+r+g) then
  call RemoveUnit(GetConstructedStructure())
  call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h005', loc, 0.0)
 else//If the number is none of the above
  if srandomn == sLandCount then//Just deciding what special building
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), sLand, loc, 0.0)
  elseif srandomn == (sLandCount-1) then//Since "sLandCount" is a unknown number in the random,
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), sLand2, loc, 0.0)
  elseif srandomn == (sLandCount-2) then//this way is used
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), sLand3, loc, 0.0)
  elseif srandomn == (sLandCount-3) then
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), sLand4, loc, 0.0)
  elseif srandomn == (sLandCount-4) then
   call RemoveUnit(GetConstructedStructure())
   call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), sLand5, loc, 0.0)
  endif
 endif
 set loc = null
endfunction

function LandRandom_Conditions takes nothing returns boolean
 return GetUnitTypeId(GetTriggerUnit()) == 'h000'//this is like the dummy building, once complete will be replaced with random building
endfunction

//function Trig_LandRandom_Actions takes nothing returns nothing
// if GetOwningPlayer(GetConstructedStructure()) == Player(0) then
//  call LandRandom_izer(udg_player0.w, udg_player0.u, udg_player0.b, udg_player0.r, udg_player0.g, udg_player0.sLandCount, udg_player0.sland, udg_player0.sland2, udg_player0.sland3, udg_player0.sland4, udg_player0.sland5)
// endif//this only works for player(0) for testing
//Ideas:
//give the argument as the player, the _izer can get the stuff from PlayerDataArray[takenplayer].w ,PlayerDataArray[takenplayer].sLandCount
//no need argument just PlayerDataArray[GetPlayerId(GetOwningPlayer(GetConstructedUnit()))].w
//endfunction

//===========================================================================
function InitTrig_LandRandom takes nothing returns nothing
    set gg_trg_LandRandom = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_LandRandom, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH)
    call TriggerAddCondition(gg_trg_LandRandom, Condition(function LandRandom_Conditions))
    call TriggerAddAction( gg_trg_LandRandom, function LandRandom_izer)
endfunction

In reply to Earth_Fury's post:
JASS:
struct playerdata// struct to keep the player data which would be needed later
 player p//not implamented yet
 unit hero//not implamented yet
 integer w//Basically these w,u,b,r,g numbers are used 
 integer u//to set different 
 integer b//poportions of randomness
 integer r//if the player chooses
 integer g//different heroes
 integer slandn//So i can adjust the amount of special building a hero would have
 integer sland// the integer of the special building of hero
 integer sland2//so is sland2 to sland5
 integer sland3
 integer sland4
 integer sland5
 
  method inputherodata takes integer w, integer u, integer b, integer r, integer g, integer slandn, integer sland, integer sland2, integer sland3, integer sland4, integer sland5 returns nothing
   set this.w = w
   set this.u = u
   set this.b = b
   set this.r = r
   set this.g = g
   set this.slandn = slandn
   set this.sland = sland
   set this.sland2 = sland2
   set this.sland3 = sland3
   set this.sland4 = sland4
   set this.sland5 = sland5
 endmethod//this method is just because i am lazy to type "set" this and that later in the coding.
endstruct
This... makes little sense.
  1. Struct names usually have the naming convention of "EveryFirstLetterInAWordIsACapitol"


  1. Ok, i dint know these naming conventions and all, BUT honestly, i can name it anything right? It would not affect how or wheter the code works. Not saying i am agaisnt naming convention , I agree to naming conventions and would happily follow them.(as you can see in my 2nd refined coding)

    [*]
    JASS:
     integer w//Basically these w,u,b,r,g numbers are used 
     integer u//to set different 
     integer b//poportions of randomness
     integer r//if the player chooses
     integer g//different heroes
    Why are you not using an array? (arrays as struct members, unlike normal arrays, have a static length. check the JASSHelper manual for more information)

    I am not using an array because if i use an array like integer array wubrg then it would only be for 1 player, thefore i would have to make one array for each player, thus i would defeat the purpose of making an array already. For Example:
    JASS:
    globals
     integer array wubrgPlayer0
     integer array wubrgPlayer1
     integer array wubrgPlayer2
     integer array wubrgPlayer3
     integer array wubrgPlayer4
     integer array wubrgPlayer5
     integer array wubrgPlayer6
     integer array wubrgPlayer7
     integer array wubrgPlayer8
    endglobals
    Unless of course i can declare arrays within structs ,then i could use arrays

    [*]
    JASS:
     integer slandn//So i can adjust the amount of special building a hero would have
     integer sland// the integer of the special building of hero
     integer sland2//so is sland2 to sland5
     integer sland3
     integer sland4
     integer sland5
    Again, why are you not using an array? And the common naming convention i see for arrays is: integer sLandCount and integer array sLands
    The reason is same as why i dint use arrays in the w,u,b,r,g.
    And i changed my code to follow the naming convention.

    [*] If a function takes more than 4 arguments (arguments are what you pass to a function as in: call MyFunc("argument 1", 2, 3) ) then you need to rethink your code. functions should only take a few arguments to keep code simple and concise. Methods are functions in this context.
Yeah ok,i refined my code so that part now takes no arguments.:wthumbsup:

JASS:
globals //struct globals for players since they are going to be acessed not just locally
 playerdata udg_player0
 playerdata udg_player1
 playerdata udg_player2
 playerdata udg_player3
 playerdata udg_player4
 playerdata udg_player5
 playerdata udg_player6
 playerdata udg_player7
 playerdata udg_player8
endglobals
Do you even know what an array is?! If you don't, i suggest you learn, then come back to this code :) anyway, use an array here. also, get rid of the udg_ prefix... it serves no purpose, as you can know what is a global by a naming convention like:
  • All global variables start in a capital letter, and each first letter of each word is a capital, ala "ThisIsAGlobal"
  • All local variables start in a lower case letter, and each first letter of each word (other than the first) is a capital, ala "thisIsALocal".

JASS:
globals
    playerdata array PlayersData
endglobals

Yeah, my bad, didnt think of arrays. Changed it already.

JASS:
function Trig_HeroType_Actions takes nothing returns nothing
 set udg_player0 = playerdata.create()//have to create it here, not gonna use it before this anyway
 set udg_player1 = playerdata.create()
 set udg_player2 = playerdata.create()
 set udg_player3 = playerdata.create()
 set udg_player4 = playerdata.create()
 set udg_player5 = playerdata.create()
 set udg_player6 = playerdata.create()
 set udg_player7 = playerdata.create()
 set udg_player8 = playerdata.create()
 if GetOwningPlayer(GetSoldUnit()) == Player(0) then// this entire thing only works for player(0) for 
  set udg_player0.hero = GetSoldUnit()              //testing.
  set udg_player0.p = Player(0)
  if GetUnitTypeId(GetSoldUnit()) == 'N002' then//Sets things up for later use 
   call udg_player0.inputherodata(10,10,0,60,0,2,'h006','h007',0,0,0)//depending on the hero bought
   //too lazy to type, so used method
  elseif GetUnitTypeId(GetSoldUnit()) == 'N006' then
   call udg_player0.inputherodata(0,0,20,0,70,3,'h006','h007','h008',0,0)
   //too lazy to type, so used method
  endif
 endif
endfunction

ignoring the fact that you're mixing struct declarations with some random trigger for now, you're doing one major thing wrong: you're initializing the struct variables for every player every time one buys a unit.

so lets split all this up. Create 2 "triggers" in the world editor, name one "PlayerData" and the other whatever. in "PlayerData", use a library with an initializer as such:
JASS:
library PlayerData initializer init

struct playerdata// struct to keep the player data which would be needed later
 player p//not implamented yet
 unit hero//not implamented yet
 integer w//Basically these w,u,b,r,g numbers are used 
 integer u//to set different 
 integer b//poportions of randomness
 integer r//if the player chooses
 integer g//different heroes
 integer slandn//So i can adjust the amount of special building a hero would have
 integer sland// the integer of the special building of hero
 integer sland2//so is sland2 to sland5
 integer sland3
 integer sland4
 integer sland5
 
  method inputherodata takes integer w, integer u, integer b, integer r, integer g, integer slandn, integer sland, integer sland2, integer sland3, integer sland4, integer sland5 returns nothing
   set this.w = w
   set this.u = u
   set this.b = b
   set this.r = r
   set this.g = g
   set this.slandn = slandn
   set this.sland = sland
   set this.sland2 = sland2
   set this.sland3 = sland3
   set this.sland4 = sland4
   set this.sland5 = sland5
 endmethod//this method is just because i am lazy to type "set" this and that later in the coding.
endstruct

globals //struct globals for players since they are going to be acessed not just locally
 playerdata udg_player0
 playerdata udg_player1
 playerdata udg_player2
 playerdata udg_player3
 playerdata udg_player4
 playerdata udg_player5
 playerdata udg_player6
 playerdata udg_player7
 playerdata udg_player8
endglobals

private function init takes nothing returns nothing
 set udg_player0 = playerdata.create()
 set udg_player1 = playerdata.create()
 set udg_player2 = playerdata.create()
 set udg_player3 = playerdata.create()
 set udg_player4 = playerdata.create()
 set udg_player5 = playerdata.create()
 set udg_player6 = playerdata.create()
 set udg_player7 = playerdata.create()
 set udg_player8 = playerdata.create()
endfunction
endlibrary

init will then be called before all InitTrig_Whatever() functions. any functions you stick in a library will also be moved to the top of the map script, allowing you to use them anywhere. (check the JASSHelper manual for more information about librarys)

if you turn sane and use an array, init would look like:
JASS:
private function init takes nothing returns nothing
    local integer i = 0
    loop
        exitwhen i > 11

        set PlayersData[i] = playerdata.create()
        set PlayersData[i].p = Player(i)

        set i = i + 1
    endloop
endfunction

In the other trigger i told you to create, you would put the rest of that crap in to it. Except you would want it coded sanely, something like:
JASS:
function Trig_HeroType_Actions takes nothing returns nothing
    local player p = GetOwningPlayer(GetSoldUnit())
    
    // using an array where you where using a bunch of globals...
    set PlayersData[GetPlayerId(p)].hero = GetSoldUnit()
    if GetUnitTypeId(GetSoldUnit()) == 'N002' then//Sets things up for later use 
        // Don't use that lame method... just write out all the needed set statements and CnP... or use a loop of some kind here
    elseif GetUnitTypeId(GetSoldUnit()) == 'N006' then
        
    endif
endfunction

//===========================================================================
function InitTrig_HeroType takes nothing returns nothing
    set gg_trg_HeroType = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_HeroType,EVENT_PLAYER_UNIT_SELL)
    call TriggerAddAction( gg_trg_HeroType, function Trig_HeroType_Actions )
endfunction

At first i didnt know where that struct and global thing should be actually so i just put it in the trigger that i would be the first to use it. Anyway i already split it into 2 triggers ,used the library and initializer , and the loop to create() the structs. It didnt come to my mid that you could call array[name] like that.

elseif srandomn == (sland-3) then sland is of the type unit... which means this is beyond wrong. (units are not numbers... and using rawcodes as numbers is a bad idea. rawcodes being 'RawC'

Ok its a typo, i should have been elseif srandomn == (slandn-3) then ,the now named elseif srandomn == (sLandCount-3) then

i still have no fucking idea what you're trying to achive in the second trigger, and im too lazy to look over it right now...
The second trigger, now the third, is just a trigger to replace the dummy building with a random building. I plan the game, so that the ratio of what random building you get are determined by the hero, therefore the trigger has all the complicated stuff so it will work no matter what hero the player uses. It is also flexible so the values can be changed easily to change the ratio and even what the random building could be, and it could be different for evry single player. Otherwise i would have to check the type of hero the player is using everytime, and a whole lot of complicated and unconcise coding.
 
Status
Not open for further replies.
Top