Help with script errors?

Morbid

New Member
Reaction score
0
Hey, I'm new to scripting in warcraft lll. I'm using newgen, and have tried to edit a script to suit my purposes.

Orignally the script checks number of items in region of certain type, if equal to or less than set number created a new of the same item checking for randomly inside of region.

Origanlly it worked for single set MIN_ITEM_COUNT (as a private constant), but I was not sure if it works as an array (as this way I could use the single script for the intire map with all items and regions and set item numbers in them.

JASS:
scope Ritems initializer Init
globals

    private constant real    INTERVAL       = 1.
    
    private integer array MIN_ITEM_COUNT
    private integer array ITEM_ID
    private integer array ITEM_COUNT
    private rect array AREA
    
    private boolexpr FILTER
endglobals

private function CountItems takes nothing returns boolean
    local integer id = GetItemTypeId(GetFilterItem())
    local integer i = 0
    
    loop
        exitwhen ITEM_ID<i> == null
        if ITEM_ID<i> == id then
            set ITEM_COUNT<i> = ITEM_COUNT<i>+1
            return false
        endif
        set i = i+1
    endloop
    return false
endfunction

private function Actions takes nothing returns nothing
    local integer i = 0
    local integer a
    
    loop
        //Looping through all of the assigned rects searching for and counting
        //the assigned item ids:
        exitwhen AREA<i> == null
        call EnumItemsInRect(AREA<i>,FILTER,function DoNothing)
        set a = 0
        loop
            //Looping through the number of assigned item ids in the rect,
            //creating an item of the type if the number is less than MIN_ITEM_COUNT.
            exitwhen ITEM_ID[a] == null
            if ITEM_COUNT[a] &lt;= MIN_ITEM_COUNT then
                call CreateItem(ITEM_ID[a],GetRandomReal(GetRectMinX(AREA<i>),GetRectMaxX(AREA<i>)),GetRandomReal(GetRectMinY(AREA<i>),GetRectMaxY(AREA<i>)))
            endif
            set ITEM_COUNT[a] = 0 //Reset the array index for next execution.
            set a = a+1
        endloop
        set i = i+1
    endloop
endfunction

function Init takes nothing returns nothing

    local trigger trig = CreateTrigger()
    
    //Items to check for:
    //&lt;--- Shallow Shores ---&gt;
    set ITEM_ID[0] = &#039;I001&#039;
    set ITEM_ID[1] = &#039;I001&#039;
    set ITEM_ID[2] = &#039;I001&#039;
    set ITEM_ID[3] = &#039;I001&#039;
    //&lt;--- Shallow Shores ---&gt;
    
    //Set Min_Item_Count:
    //&lt;--- Shallow Shores ---&gt;    
    set MIN_ITEM_COUNT[0] = 4
    set MIN_ITEM_COUNT[1] = 1
    set MIN_ITEM_COUNT[2] = 2
    set MIN_ITEM_COUNT[3] = 3
    //&lt;--- Shallow Shores ---&gt;
    
    //Define rects to check in:
    //&lt;--- Shallow Shores ---&gt;
    set AREA[0] = (gg_rct_Shore_Shallows)
    set AREA[1] = (gg_rct_Shore_Shallows_1)    
    set AREA[2] = (gg_rct_Shore_Shallows_2)
    set AREA[3] = (gg_rct_Shore_Shallows_3)
    //&lt;--- Shallow Shores ---&gt;

    
    call TriggerRegisterTimerEvent(trig,INTERVAL,true)
    call TriggerAddAction(trig,function Actions)
    set FILTER = Condition(function CountItems)
endfunction
endscope
</i></i></i></i></i></i></i></i></i></i>


MIN_ITEM_COUNT doesn't work, and in testing the map just constantly creates the item every second. Anyone able to shed some light on this for me? Thanks.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
JASS:
    set ITEM_ID[0] = &#039;I001&#039;
    set ITEM_ID[1] = &#039;I001&#039;
    set ITEM_ID[2] = &#039;I001&#039;
    set ITEM_ID[3] = &#039;I001&#039;


Why use an array if they are all the same value? You could easily change this to:

JASS:
private integer ITEM_ID = &#039;I001&#039;


There's no reason to iterate the ITEM_ID. All it will do is possibly crash the thread once you start going outside of the array range. I've added a debug message to the function below. Try running it, if you don't see a debug message you aren't picking up any of the items.

JASS:
private function CountItems takes nothing returns boolean
    local integer id = GetItemTypeId(GetFilterItem())
    local integer i = 0
    
    loop
        exitwhen ITEM_ID == null
        if ITEM_ID == id then
            call BJDebugMsg(&quot;Incrementing ITEM_COUNT&quot;)
            set ITEM_COUNT<i> = ITEM_COUNT<i>+1
            return false
        endif
        set i = i+1
    endloop
    return false
endfunction</i></i>
 

Morbid

New Member
Reaction score
0
Reason for having the same item, is this is the map so far, I'm adding more items and regions. This is only for one section of the map, I didn't know there was a max for the array? I was hoping to go to about 100, for example:
JASS:
    //Items to check for:
    //&lt;--- Shallow Shores ---&gt;
    set ITEM_ID[0] = &#039;I001&#039;
    set ITEM_ID[1] = &#039;I001&#039;
    set ITEM_ID[2] = &#039;I001&#039;
    set ITEM_ID[3] = &#039;I001&#039;
    //&lt;--- Barran Plains ---&gt;
    set ITEM_ID[4] = &#039;I002&#039;
    set ITEM_ID[5] = &#039;I002&#039;
    set ITEM_ID[6] = &#039;I002&#039;
    set ITEM_ID[7] = &#039;I002&#039;
    //&lt;--- Dark Forrest ---&gt;
    set ITEM_ID[8] = &#039;I003&#039;
    set ITEM_ID[9] = &#039;I003&#039;
    set ITEM_ID[10] = &#039;I003&#039;
    set ITEM_ID[11] = &#039;I003&#039;
   //&lt;--- etc, etc


I also thought that all the arrays are connacted to each other?
as in:
ITEM_ID[0] corresponds to MIN_ITEM_COUNT[0] and to AREA[0]

If not, then I will just make a trigger for each item and each min item count.

I will try your debug soon.
 

Morbid

New Member
Reaction score
0
"Incrementing ITEM_COUNT"

I beleive its to do with my MIN_ITEM_COUNT

I think I will just create many triggers instead of using just one big one, unless there is another way around it?

morbid.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Ah yes, it does. You never set MIN_ITEM_COUNT to a value. You need to do that before it will work.
 

Morbid

New Member
Reaction score
0
Yes, I had an array, and just thought I would follow the other two arrays and add it at the bottom like so, but it doesn't work like that :(

JASS:

    //Set Min_Item_Count:
    //&lt;--- Shallow Shores ---&gt;    
    set MIN_ITEM_COUNT[0] = 4
    set MIN_ITEM_COUNT[1] = 1
    set MIN_ITEM_COUNT[2] = 2
    set MIN_ITEM_COUNT[3] = 3
    //&lt;--- Shallow Shores ---&gt;
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
The way you have this setup is kind of confusing. :X I keep missing the array part in your declarations. Kind of out of it tonight...
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top