| 05-02-2008, 11:53 AM | #1 |
Im having trouble assigning an item to a global array of items very weird, or i just dont understand items at all. array is 0 - 10 i have a set i = CreateItem (udg_nextItem[p], udg_itemlocx , udg_itemlocy ) set udg_item[p] = i if i run a BJDebugMsg BJDebugMsg("Item p is " + GetItemName(udg_item[p])) it will return its name just fine. Now if i run a BJDebugMsg Externally ie from another function say function test Loop exitwhen i > 10 BJDebugMsg("Item " + I2S(i) + GetItemName(udg_item[p])) endloop This will return item 1 is "Item" item 2 is <-- this is empty item 3 is "item" item 4 is "item" item 5 is <--- empty item 6 is <-- empty *BTW* this is just off the top of my head not the actual results etc all the way to 10. I seem to have noticed a pattern that every other item is a null. Figuring it could be a pointer issue, i type casted it to a handle and displayed all the handles *which were fine* each item had its own unique handle/pointer. Then i tried type casting it back to item using the return bug. Still have the problem of some items being null. This has bugged me for a good few days now ... im asking here as a last resort to this problem I have uploaded the map i am working on which has the problem this is code of problem JASS:function hz takes nothing returns nothing local integer p = GetPlayerId(GetOwningPlayer(GetEnumUnit())) local item i = null if udg_debughz then call BJDebugMsg(GetPlayerName(Player(p)) + " is in home zone") endif set udg_idle[p] = udg_idle[p] + 1 // If cpu has been in hz for 20 seconds force him to make a choice if udg_buying[p] == false or udg_idle[p] > 100 then // Player has enough gold for its next item, so go buy it if GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_GOLD) >= itemCosts(udg_nextItem[p]) then set udg_buying[p] = true // Create the item the unit is going to buy at a hidden location call LockMutex("I") set udg_itemlocx = udg_itemlocx + 50 set i = CreateItem (udg_nextItem[p], udg_itemlocx , udg_itemlocy ) call UnlockMutex("I") set udg_item[p] = H2I(i) call GotoBuyZone2(p) set udg_buying[p] = false elseif inHealZone(p) then set udg_buying[p] = false call unitHealed(p) else set udg_buying[p] = false set udg_idle[p] = 0 call GotoHealZone(p) endif endif endfunction |
| 05-02-2008, 12:18 PM | #2 |
So, crazy theory, but is the item removed between those functions' executions? |
| 05-02-2008, 12:41 PM | #3 |
Haha... sounds crazy but its true ... or im doing something wrong.. No item is removed. If you try the map, the items are created at some point on the map where i can see them. From the code you can see that item "i" has been assigned to udg_item[p]. and when you do a debug message after that line .. it will say udg_item[p] = (the item assigned to it). Now when you run it externally "in my knowledge" there is actually an array of items attached to the udg_item[p] <- pointers, each had a different pointer/handle value. Now in my map .. a unit is supposed to pick up the created item assigned to each of the udg_item arrays but only some of them do pick it up the rest are left on the ground. -- *hrmp* im not very good at explaining and describing -- it'll be easier if i showed you |
| 05-02-2008, 02:24 PM | #4 |
How was your pattern again? Maybe you´re overlapping the first item in the array but skipping the next and so on. In that case 5 item names will probably show... |
| 05-02-2008, 04:47 PM | #5 |
line 170 in AI should be replaced from this set i = call UnitAddItemById(udg_CPU[p], udg_nextItem[p]) to: set i = UnitAddItemById(udg_CPU[p], udg_nextItem[p]) or else it won't even save. Maybe it's something to do with how your setting the items try displaying debug messages to the value i has seeing if i is getting set right. -------------------------------------------------------------------- Theres something wrong going on your looping the creation of the items somehow and you're creating massive amounts of items and probably setting the item variable over and over to the same thing. My guesss... is that using a function with: takes nothing returns nothing and a if then else thing is that it is somehow continuously running it too much that way. |
| 05-02-2008, 05:16 PM | #6 |
post those mutex stuff, btw I think any mutex implementation in Jass is doomed to fail. |
| 05-02-2008, 05:50 PM | #7 |
hmm this over lapping. can you explain it in more detail and how to fix it? i just assumed assigning items to a item array is just as simple as set udg_items[p] = i. when i tested it, each item has a different pointer. Wouldnt that be enough to show that they are all different? The mutex stuff makes no difference btw, i been testing out a variety of things such as making each cpu access the variable at a time. so ignore the mutex as it will be same outcome if it wernt there |
| 05-02-2008, 05:53 PM | #8 |
You shouldn't worry about that stuff in Jass, yeah really, only one core is used by it, dunno about the rest of the game though... |
| 05-02-2008, 06:22 PM | #9 |
hmm.... this is just gona be an endless cycle of testing for me ... it just seems that ive tried every possible way and the outcome is the same ... unless i change the system but when i use UnitAddItemById it seems to lag, but it lags when UnitAddItem is used anyway ... could it be problems with the custom items? im going to post a screenshot as shown in the screen 10 items have been created in the red box. this is the code JASS:function unitHealed takes integer p returns nothing if (GetUnitLifePercent(udg_CPU[p]) >= 95.00) then call GotoBattleZone(p) endif endfunction //************************************************************ //** For Every Unit in either red or blue Home zones are made to go //** buy item if they satisfy criteria or go to battle zone once //** fully healed //************************************************************ // For every CPU in the blue home zone function hz takes nothing returns nothing local integer p = GetPlayerId(GetOwningPlayer(GetEnumUnit())) local item i = null local integer a = 0 if udg_debughz then call BJDebugMsg(GetPlayerName(Player(p)) + " is in home zone") endif set udg_idle[p] = udg_idle[p] + 1 // If cpu has been in hz for 20 seconds force him to make a choice if udg_buying[p] == false or udg_idle[p] > 100 then set udg_idle[p] = 0 // Player has enough gold for its next item, so go buy it if GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_GOLD) >= itemCosts(udg_nextItem[p]) then set udg_buying[p] = true // Create the item the unit is going to buy at a hidden location call LockMutex("I") set udg_itemlocx = udg_itemlocx + 50 set udg_item[p] = CreateItem (udg_nextItem[p], udg_itemlocx , udg_itemlocy ) call UnlockMutex("I") call GotoBuyZone2(p) elseif inHealZone(p) then call BJDebugMsg("In heal Zone") set udg_buying[p] = false call unitHealed(p) else set udg_buying[p] = false call GotoHealZone(p) endif endif endfunction JASS:function items takes nothing returns nothing local integer i = 0 loop exitwhen i > 9 call BJDebugMsg(GetPlayerName(Player(i)) + "'s item is " + GetItemName(udg_item[i])) call BJDebugMsg(GetPlayerName(Player(i)) + " item handle is " + I2S(H2I(udg_item[i]))) set i = i + 1 endloop endfunction |
| 05-02-2008, 06:36 PM | #10 |
It may be a problem in the GetItemName() native, I've never seen anyone use it for anything before now. Try GetObjectName(GetItemTypeId(udg_item[i])) instead and see if it works. (You may need to play with that syntax, I forget exactly the argument/function nomenclature for those calls) |
| 05-02-2008, 06:49 PM | #11 |
Object name does no difference other than change *empty* to default string look at 1st screen JASS:
call LockMutex("I")
set udg_itemlocx = udg_itemlocx + 50
set udg_item[p] = CreateItem (udg_nextItem[p], udg_itemlocx , udg_itemlocy )
call UnlockMutex("I")
call BJDebugMsg("Created Item " + GetItemName(udg_item[p]))
with that debug msg there 2nd ss shows the result So yeh ... the udg_item[p] can be locally in the function. but when used in an external function it seems to be messed up. suggestions? or is global item array officially bugged? |
| 05-02-2008, 07:06 PM | #12 |
oh btw ... there are 10 threads running simultaneously .. but in theory it shouldnt cause problems to the item assignment right? |
| 05-02-2008, 08:21 PM | #13 | |
Quote:
|
| 05-02-2008, 08:39 PM | #14 |
but isnt it weird that the debug message displays the name correctly right after it was created. I called the loop to display the item names and handles right after all the udg_item array has been allocated. no other part of the code uses udg_item but this assignment part and the display part. I really cant think of what is causing this problem other than *bug* The other part that uses udg_item has been commented out for testing purposes, so thats not affecting anything. That part is when a unit picks up this created item. But only the units that actually have the item name displayed as *item name* *not as default string or nothing* will actually pick up the item. The rest are left on the floor. Hmm i fink i've tested this a few days ago as well ... i might have to try reproduce this proof, but it seems the units not picking anything up displays a message "item is 0" <-- where i did GetItemTypeId(udg_item[p]) maybe i should try reproduce this error on a clean map. You might be right that something is messing with the handles |
