• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

[solved] Bug while initializing mass market

Status
Not open for further replies.
Level 2
Joined
Apr 4, 2022
Messages
13
Hello everybody, I'm having a little bug on one of my latest trigger and i'm out of ideas so I come here seeking help and knowledge.
I'm new here tell me if i mess up !

I've been developping a pirates themed map for a bit of time and I am trying to build a market system where in the init of the map, each market would be assigned 5 random tradeable items out of 15 initialized in the tradeable goods list (each picked item class is put at the end of the list, and the limit is length-a to ensure uniqueness), then one is randomly picked as the cheap good (the offer) and another one is picked randomly from the 1 to 15 items of the tradeable goods list (to ensure they are not sold there, and become the Demand) and dummy abilities tooltip are filed to display offer and demand to the player. here is the code :

  • -------- ---------------------------------------- --------
  • -------- Init tradeable good list --------
  • -------- ---------------------------------------- --------
  • Set VariableSet tradeableGoods[1] = Beer Keg
  • Set VariableSet tradeableGoods[2] = Chocolate
  • Set VariableSet tradeableGoods[3] = Coffee
  • Set VariableSet tradeableGoods[4] = Ebony
  • Set VariableSet tradeableGoods[5] = Flax
  • Set VariableSet tradeableGoods[6] = Furs
  • Set VariableSet tradeableGoods[7] = Gold
  • Set VariableSet tradeableGoods[8] = Mahogany
  • Set VariableSet tradeableGoods[9] = Rum
  • Set VariableSet tradeableGoods[10] = Silk
  • Set VariableSet tradeableGoods[11] = Silver
  • Set VariableSet tradeableGoods[12] = Spices
  • Set VariableSet tradeableGoods[13] = Sugar
  • Set VariableSet tradeableGoods[14] = Tobacco
  • Set VariableSet tradeableGoods[15] = Whale oil
  • -------- ---------------------------------------- --------
  • -------- Init markets --------
  • -------- ---------------------------------------- --------
  • Set VariableSet Markets = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Market))
  • Unit Group - Pick every unit in Markets and do (Actions)
    • Loop - Actions
      • -------- ---------------------------------------- --------
      • -------- init sold items --------
      • -------- ---------------------------------------- --------
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • Set VariableSet itemTypeTempId = (Random integer number between 1 and (16 - (Integer A)))
          • Set VariableSet itemTypeTemp = tradeableGoods[itemTypeTempId]
          • Neutral Building - Add itemTypeTemp to (Picked unit) with 1 in stock and a max stock of 10
          • Set VariableSet tradeableGoods[itemTypeTempId] = tradeableGoods[(16 - (Integer A))]
          • Set VariableSet tradeableGoods[(16 - (Integer A))] = itemTypeTemp
          • Set VariableSet itemTypeTempList[(Integer A)] = itemTypeTemp
      • -------- ---------------------------------------- --------
      • -------- init good in surplus --------
      • -------- ---------------------------------------- --------
      • Set VariableSet itemTypeTemp = itemTypeTempList[(Random integer number between 1 and 5)]
      • Set VariableSet itemTemp = (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to itemTypeTemp))
      • Ability - Set Tooltip of Offer to (Offer : + (Name of itemTemp)) for level marketNumber
      • Ability - Set Extended Tooltip of Offer to (Description of itemTemp) for level marketNumber
      • Unit - Set level of Offer for (Picked unit) to marketNumber
      • -------- ---------------------------------------- --------
      • -------- init wanted goods --------
      • -------- ---------------------------------------- --------
      • Set VariableSet itemTypeTemp = tradeableGoods[(Random integer number between 1 and 10)]
      • Set VariableSet itemTemp = (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to itemTypeTemp))
      • Ability - Set Tooltip of Demand to (Demand : + (Name of itemTemp)) for level marketNumber
      • Ability - Set Extended Tooltip of Demand to (Description of itemTemp) for level marketNumber
      • Unit - Set level of Demand for (Picked unit) to marketNumber
      • Set VariableSet marketNumber = (marketNumber + 1)
For some reason, the tooltip get all messed up. I test this using three markets, and one is never initialized at all and the tooltips of the other ones don't match the code. It looks a bit like the a(0) is never initialized, a(1) = a(o) and a(2) = a(3).

Thanks you for your time !
 
Last edited:
Level 2
Joined
Apr 4, 2022
Messages
13
If I add some debug messages like so :

  • Unit Group - Pick every unit in Markets and do (Actions)
    • Loop - Actions
      • Set VariableSet marketNumber = (marketNumber + 1)
      • -------- ---------------------------------------- --------
      • -------- init sold items --------
      • -------- ---------------------------------------- --------
      • Game - Display to (All players) the text: (String(marketNumber))
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • Set VariableSet itemTypeTempId = (Random integer number between 1 and (16 - (Integer A)))
          • Set VariableSet itemTypeTemp = tradeableGoods[itemTypeTempId]
          • Neutral Building - Add itemTypeTemp to (Picked unit) with 1 in stock and a max stock of 10
          • Set VariableSet tradeableGoods[itemTypeTempId] = tradeableGoods[(16 - (Integer A))]
          • Set VariableSet tradeableGoods[(16 - (Integer A))] = itemTypeTemp
          • Set VariableSet itemTypeTempList[(Integer A)] = itemTypeTemp
      • -------- ---------------------------------------- --------
      • -------- init good in surplus --------
      • -------- ---------------------------------------- --------
      • Set VariableSet itemTypeTemp = itemTypeTempList[(Random integer number between 1 and 5)]
      • Set VariableSet itemTemp = (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to itemTypeTemp))
      • Ability - Set Tooltip of Offer to ((Offer level + (String(marketNumber))) + (Name of itemTemp)) for level marketNumber
      • Ability - Set Extended Tooltip of Offer to (Description of itemTemp) for level marketNumber
      • Unit - Set level of Offer for (Picked unit) to marketNumber
      • Game - Display to (All players) the text: (Name of itemTemp)
      • -------- ---------------------------------------- --------
      • -------- init wanted goods --------
      • -------- ---------------------------------------- --------
      • Set VariableSet itemTypeTemp = tradeableGoods[(Random integer number between 1 and 10)]
      • Set VariableSet itemTemp = (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to itemTypeTemp))
      • Ability - Set Tooltip of Demand to ((Demand+ (String(marketNumber))) : + (Name of itemTemp)) for level marketNumber
      • Ability - Set Extended Tooltip of Demand to (Description of itemTemp) for level marketNumber
      • Unit - Set level of Demand for (Picked unit) to marketNumber
      • Game - Display to (All players) the text: (Name of itemTemp)
One of the market (the one without correct init tooltips) has lvl 2 Offer/Demand as well as one of the market. However, the item sold by all markets are correctly initialized. It also seems with the game - messages that the loop works correctly.

EDIT :
So, i made big changes because i notices that in fact, only the tooltip itself is bugging. I decided to transmit data via integer field that i don't otherwise use (level and formation rank) and to display it using a spell. Here is the code :

  • init
    • Events
      • Map initialization
      • Time - Elapsed game time is 0.10 seconds
    • Conditions
    • Actions
      • -------- ---------------------------------------- --------
      • -------- Init tradeable good list --------
      • -------- ---------------------------------------- --------
      • Set VariableSet tradeableGoods[1] = Beer Keg
      • Set VariableSet tradeableGoods[2] = Chocolate
      • Set VariableSet tradeableGoods[3] = Coffee
      • Set VariableSet tradeableGoods[4] = Ebony
      • Set VariableSet tradeableGoods[5] = Flax
      • Set VariableSet tradeableGoods[6] = Furs
      • Set VariableSet tradeableGoods[7] = Gold
      • Set VariableSet tradeableGoods[8] = Mahogany
      • Set VariableSet tradeableGoods[9] = Rum
      • Set VariableSet tradeableGoods[10] = Silk
      • Set VariableSet tradeableGoods[11] = Silver
      • Set VariableSet tradeableGoods[12] = Spices
      • Set VariableSet tradeableGoods[13] = Sugar
      • Set VariableSet tradeableGoods[14] = Tobacco
      • Set VariableSet tradeableGoods[15] = Whale oil
      • -------- ---------------------------------------- --------
      • -------- Init markets --------
      • -------- ---------------------------------------- --------
      • Set VariableSet Markets = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Market))
      • Unit Group - Pick every unit in Markets and do (Actions)
        • Loop - Actions
          • -------- ---------------------------------------- --------
          • -------- init sold items --------
          • -------- ---------------------------------------- --------
          • For each (Integer A) from 1 to 5, do (Actions)
            • Loop - Actions
              • Set VariableSet itemTypeTempId = (Random integer number between 1 and (16 - (Integer A)))
              • Set VariableSet itemTypeTemp = tradeableGoods[itemTypeTempId]
              • Neutral Building - Add itemTypeTemp to (Picked unit) with 1 in stock and a max stock of 10
              • Set VariableSet tradeableGoods[itemTypeTempId] = tradeableGoods[(16 - (Integer A))]
              • Set VariableSet tradeableGoods[(16 - (Integer A))] = itemTypeTemp
              • Set VariableSet itemTypeTempList[(Integer A)] = itemTypeTemp
          • -------- ---------------------------------------- --------
          • -------- init Offer --------
          • -------- ---------------------------------------- --------
          • Set VariableSet itemTypeTemp = itemTypeTempList[(Random integer number between 1 and 5)]
          • Set VariableSet itemTemp = (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to itemTypeTemp))
          • Unit - Set Unit: (Picked unit)'s Integer Field: Level ('ulev') to Value: (Integer((Description of itemTemp)))
          • -------- ---------------------------------------- --------
          • -------- init Demand --------
          • -------- ---------------------------------------- --------
          • Set VariableSet itemTypeTemp = tradeableGoods[(Random integer number between 1 and 10)]
          • Set VariableSet itemTemp = (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to itemTypeTemp))
          • Unit - Set Unit: (Picked unit)'s Integer Field: Formation Rank ('ufor') to Value: (Integer((Description of itemTemp)))
      • -------- ---------------------------------------- --------
      • -------- Reinit tradeable good list --------
      • -------- ---------------------------------------- --------
      • Set VariableSet tradeableGoods[1] = Beer Keg
      • Set VariableSet tradeableGoods[2] = Chocolate
      • Set VariableSet tradeableGoods[3] = Coffee
      • Set VariableSet tradeableGoods[4] = Ebony
      • Set VariableSet tradeableGoods[5] = Flax
      • Set VariableSet tradeableGoods[6] = Furs
      • Set VariableSet tradeableGoods[7] = Gold
      • Set VariableSet tradeableGoods[8] = Mahogany
      • Set VariableSet tradeableGoods[9] = Rum
      • Set VariableSet tradeableGoods[10] = Silk
      • Set VariableSet tradeableGoods[11] = Silver
      • Set VariableSet tradeableGoods[12] = Spices
      • Set VariableSet tradeableGoods[13] = Sugar
      • Set VariableSet tradeableGoods[14] = Tobacco
      • Set VariableSet tradeableGoods[15] = Whale oil
      • -------- ---------------------------------------- --------
      • -------- init goods value --------
      • -------- ---------------------------------------- --------
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[1])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[2])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[3])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[4])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[5])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[6])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[7])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[8])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[9])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[10])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[11])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[12])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[13])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[14])) to 100
      • Item - Set the custom value of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[15])) to 100
  • tradingInfo
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Trading information
    • Actions
      • Game - Display to (Player group((Owner of (Casting unit)))) the text: (Offered : + (Name of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[(Unit: (Target unit of ability being cast)'s Integer Field: Level ('ulev'))]))))
      • Game - Display to (Player group((Owner of (Casting unit)))) the text: (Demanded : + (Name of (Random item in initItems <gen> matching ((Item-type of (Matching item)) Equal to tradeableGoods[(Unit: (Target unit of ability being cast)'s Integer Field: Formation Rank ('ufor'))]))))
  • Offer
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Unit-type of (Selling unit)) Equal to Market
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Integer((Description of (Sold Item)))) Equal to (Unit: (Selling unit)'s Integer Field: Level ('ulev'))
        • Then - Actions
          • Floating Text - Create floating text that reads High Offer for boug... at (Position of (Selling unit)) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds
          • Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
          • Player - Add ((Custom value of (Random item in initItems <gen> matching ((Item-type of (Sold Item)) Equal to (Item-type of (Matching item))))) x 1) to (Owner of (Buying unit)).Current gold
        • Else - Actions
  • Demand
    • Events
      • Unit - A unit Pawns an item (to shop)
    • Conditions
      • (Unit-type of (Buying unit)) Equal to Market
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Integer((Description of (Sold Item)))) Equal to (Unit: (Buying unit)'s Integer Field: Formation Rank ('ufor'))
        • Then - Actions
          • Floating Text - Create floating text that reads High demand for sol... at (Position of (Selling unit)) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds
          • Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
          • Player - Add 100 to (Owner of (Selling unit)).Current gold
        • Else - Actions
I reinit the list of good so theirs position in the array is the same as the id in their description, and the other init phase is used to store the gold value of the item (because for some reason blizzard decided it wasn't necessary to be able to access it), to calculate the discount/bonus pay.

Still, while it seems to work fine, intels about offer and demand still are wrong : they sometime offer unsold items and simply don't work, while the demand and offer trigger seem to work properly
 
Last edited:
Level 12
Joined
Feb 5, 2018
Messages
538
Click edit thread (since you created it) and choose Solved. The thread will stay open, but it will be marked as solved, so most people won't read it. :)
 
Status
Not open for further replies.
Top