Announcement

Collapse
No announcement yet.

Question: How to access InventoryItem _data in UScript?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Question: How to access InventoryItem _data in UScript?

    Hi!

    I'm using the default InventorySlot class provided on the GFX UDK library to build my game inventory.

    I need to change the Icons through "data.asset" but I don't know how to access it (since is a private var), I'm using frame labels to switch between the frames.

    Do you can please point how do I can achieve this through UScript?


    Thank you in advance.

    #2
    You can use simple method.

    Code:
    UC side.
    function SetAsset(int iAsset)
    {
         ActionScriptVoid("SetAsset");
    }
    
    AS side.
    function SetAsset(iAsset:Number)
    {
        Object.data.asset = iAsset;
    }

    Comment


      #3
      TIME TO HACK!!!! Huahaha

      @zicma:Thanks by your answer zicma, I also figured that hack the as component is the easiest way, but I'm really curious about how to send an entire object to AS using getter and setters, with some luck Mr. Doyle could clarify this after.

      Well, sharing here the tests with the InventorySlot class, I didn’t figured yet how to feed the data field with a single object through the setters and getters, but got some progress on switching the asset field…

      My itemslot movie is a bit different from the default movie from the Inventory Demo, I preferred to use frame labels with all the item types targeting easy attribution since “Dagger” or whatever will be also the internal name from the weapon. Another difference is that I have no use to stackable items, so I’ll not use quantity.

      So, first did the asset only movie with labels:

      [shot]http://i156.photobucket.com/albums/t22/creasso/UDK/03_30_IconMovie.jpg[/shot]

      Placed it into my changed/skinned component layer:

      [shot]http://i156.photobucket.com/albums/t22/creasso/UDK/03_30_Component.jpg[/shot]

      And finally, replicated components through the inventory area giving name to instances to after have a way to reffer to then on Uscript:

      [shot]http://i156.photobucket.com/albums/t22/creasso/UDK/03_30_placement.jpg[/shot]

      To feed the data, I changed the InventorySlot component (the .AS file) with a new function where I point what the _data object must contain, if worked to setter, a getter can be easily done after:

      [shot]http://i156.photobucket.com/albums/t22/creasso/UDK/03_30_ASCODE.jpg[/shot]

      Saved all, republished, reimported and saved the package on Ueditor., now the code tests:

      First test was using the Invoke method (I know that it’s slower but I just wanted to test), did this with a dummy function called FeedInventorySlots( ) that I called when the inventory is open.

      Invoke version:

      Code:
      function FeedInventorySlots()
      {
      	local GFxObject SlotWidget;
      	local ASValue NewValue;
      	local array<ASValue> ASParms;
      	
      	Advance(0);
      
      	SlotWidget = GetVariableObject("Char_Inv.BSlot_00");
      
      	NewValue.Type = AS_String;
      	NewValue.s = "Armor";
      
      	ASParms[0] = NewValue;
      	
      	NewValue.Type = AS_String;
      	NewValue.s = "Sword";
      	
      	ASParms[1] = NewValue;
      	
      	if ( SlotWidget != None ) 
      	{
      		SlotWidget.Invoke("SetData",ASParms);
      	}
      	else
      		`log("NULL");
      }
      Worked! So I read a bit about the faster method, got the subclass one:

      First, you need to create an extended GfxObject class to hold your faster style function:

      Code:
      Newfile GFxInternalSlot.uc
      
      class GFxInternalSlot extends GFxObject;
      
      // This class until now has the only goal of hold the wrapper
      // on bottom:
      function SetSlotData(string SlotType, string SlotAsset)
      {
      // Call to our inserted function
      	ActionScriptVoid("SetData");
      }
      
      DefaultProperties
      {
      }
      Back to the HUDMovie file, I rewrote the FeedInventorySlots( ) to use the subclass and the faster method:

      Code:
      function FeedInventorySlots()
      {
      	local GFxInternalSlot SlotWidget;
      	
      	Advance(0);
      
      	SlotWidget = GFxInternalSlot(GetVariableObject("Char_Inv.BSlot_00", class'GFxInternalSlot'));
      
      	if ( SlotWidget != None ) 
      	{
      		SlotWidget.SetSlotData("Weapon", "Dagger");
      	}
      	else
      		`log("NULL");
      }
      The Hack until now works pretty well ^^, hope that this samples help some more people.

      Best Wishes!

      Comment


        #4
        Your code look like my code but I'm throws all list of data into the flash.

        Code:
        function SetInventory(SETSLOT_TYPE eSetSlotType,out array<ITEM_TEMPLATE> atItem)
        {
        	local ITEM_TEMPLATE stItem;
        	local int i;
        	local array<string> arsType,arsRare,arsDup,arsTrade,arsTmp1,arsTmp2,arsTmp3,arsTmp4,arsTmp5,arsID,arsName;
        	local array<int> ariAsset,ariIndex,ariCurQuantity,ariMaxQuantity,ariSellPrice;
        
        	for(i=0;i<atItem.Length;i++)
        	{
        		stItem = atItem[i];
        		if(stItem.eMainType == MIT_USEABLE)
        		{//9-12
        			arsTmp1.AddItem(string(GetEnum(enum'USEABLE_TYPE', stItem.stUseableDT.eUseableType)));
        			arsTmp2.AddItem(string(Round(stItem.stUseableDT.stDurationTime.fFix)));
        			arsTmp3.AddItem(string(Round(stItem.stUseableDT.stReuseTime.fFix)));
        			arsTmp4.AddItem(string(stItem.stUseableDT.iHealingTime));
        			arsTmp5.AddItem("");
        		}
        		//-------------- each of item type ----------------//
        		arsType.AddItem(string(GetEnum(enum'MAINITEM_TYPE', stItem.eMainType)));
        		arsRare.AddItem(string(GetEnum(enum'RARE_TYPE', stItem.stGlobalDT.eRareType)));
        		arsDup.AddItem(string(GetEnum(enum'DUPLICATE_TYPE', stItem.stGlobalDT.eDuplicateType)));
        		arsTrade.AddItem(string(GetEnum(enum'TRADEABLE_TYPE', stItem.stGlobalDT.eTradeableType)));
        		arsID.AddItem(stItem.sID);
        		arsName.AddItem(stItem.sName);
        		ariAsset.AddItem(stItem.iAsset);
        		ariIndex.AddItem(stItem.iIndexOfFlash);
        		ariCurQuantity.AddItem(stItem.stGlobalDT.iCurQuantity);
        		ariMaxQuantity.AddItem(stItem.stGlobalDT.iMaxQuantity);
        		ariSellPrice.AddItem(stItem.stGlobalDT.iPriceSell);
        	}
        
        	if(eSetSlotType == MAIN_INVENTORY)
        	{
        		ClearMInv();//Clear before new load.
        		SetMInvData(arsType,arsID,arsName,ariAsset,ariIndex,ariCurQuantity,ariMaxQuantity,ariSellPrice,arsRare,arsDup,arsTrade,arsTmp1,arsTmp2,arsTmp3,arsTmp4,arsTmp5);
        	}
        }
        Code:
        //AS ref.Load inventory data to flash store.
        function SetMInvData(
        	array<string> sMainType,
        	array<string> sID,
        	array<string> sName,
        	array<int> iAsset,
        	array<int> iIndexOf,
        	array<int> iQauntity,
        	array<int> iMaxQauntity,
        	array<int> iSellPrice,
        	array<string> sRare,
        	array<string> sDup,
        	array<string> sTrade,
        	array<string> sTmp1,
        	array<string> sTmp2,
        	array<string> sTmp3,
        	array<string> sTmp4,
        	array<string> sTmp5
        	)
        {
        	ActionScriptVoid("SetMInvData");
        }
        AS side.
        Code:
        function SetMInvData(
        					 MainType:Array, 
        					 SID:Array, 
        					 Name:Array, 
        					 iAsset:Array, 
        					 IndexOf:Array, 
        					 Qauntity:Array, 
        					 MaxQauntity:Array, 
        					 SellPrice:Array,
        					 Rare:Array,
        					 Dup:Array,
        					 Trade:Array,
        					 Tmp1:Array,
        					 Tmp2:Array,
        					 Tmp3:Array,
        					 Tmp4:Array,
        					 Tmp5:Array
        					 )
        {
        	for(var di:Number=0;di<MainType.length;di++)
        	{
        		var Data:Object = [{
        						   type:MainType[di], 
        						   sid:SID[di], 
        						   sname:Name[di], 
        						   asset:iAsset[di], 
        						   index:IndexOf[di], 
        						   quantity:Qauntity[di], 
        						   max:MaxQauntity[di], 
        						   sellprice:SellPrice[di],
        						   rare:Rare[di],
        						   dup:Dup[di],
        						   trade:Trade[di],
        						   tmp1:Tmp1[di],
        						   tmp2:Tmp2[di],
        						   tmp3:Tmp3[di],
        						   tmp4:Tmp4[di],
        						   tmp5:Tmp5[di]
        						   }];
        		for (var i:Number = 0; i < MaxInvSlot; i++)
        		{
        			if (i == IndexOf[di])
        			{
        				InvBuff.InvSlot.sm["slot" + i].data = Data[0];
        				break;
        			}
        		}
        	}
        }
        In the first time to set item data,it will get slow with index reference finding.
        but after that it will can access to update/remove/insert by index.
        This optimized for multi-player item list and save memory.

        For flash movie I add only asset image at specify keyframe for access by ITEM ID.

        Maybe I will optimize my code again.
        >> Lastest work : RPG Inventory
        http://www.youtube.com/watch?v=4hKkxSWh4AY

        Comment


          #5
          @zicma: Your code and your inventory videos are pretty impressive, showing that you certainly has a lot more AS knowledge than myself (LOL) and also that your items will require a lot more data than mine. Personally I'm trying avoid heavy AS coding on my game, just using it when it's highly necessary. About memory, I didn't reached the optimization stage yet, but I bet that less AS stuff running best performance I'll get.

          When the time comes I'll post some benchmarks from the game monitoring tool .

          BUMP: "I still curious about how to use getter and setter on Unreal Script to send Objects to an AS private variable" LOL

          Comment


            #6
            About private variable of any class may you can access by personally public function same as C++ friend function (or your additional function in InventorySlot.as ), Because OOP concept must encapsulate all data of the class.

            I don't know the easier way to access it with Unrealscript.
            But I know only properties get/set by UC like this.

            GFXObject.Setbool("_visible",false);
            or
            fPosX = GFXObject.Getfloat("_x");

            Matt Doyle <<<<< He know this. Waiting him for answer.

            ---
            For AS code and UC code, If you know the concept of inventory working
            you can do everything if you want.
            I can move out AS method to process in UC anytime,That's not important ( if speed of processing is equal ).
            But I'm interesting in how to manage a lot of data and contents with clearly code.

            My imagination about UC and AS,I put the concept of working look like Server and Client
            programming.I will try to not control/access every object in Flash by UC
            ( some action on flash cannot control by UC i.e. Drag/Drop )
            Then I separate the work (process) and communicate with only data and call function.

            Happy to have shared the experience.

            Comment


              #7
              Use: SetWidget ( string Member, GFxObject val )

              Code:
              MyGFxObject.SetWidget("data", MyObject);

              Comment


                #8
                @Matt Doyle:Thanks by the answer Mr. Doyle! Also sorry by miss this on the docs .

                @zicma:It's nice talk with you since we are using different approachs relating GFx. In really, most of my avoidance on use AS is because my lack of deep knowledge regarding it, so, since I'm now pretty comfortable with UScript I'll reserve GFx just to showing graphics and animation. If you are interested on discuss approach, I think better we start a thread on programming or use PMs to keep this thread just to the question.

                Question answered at 04/01/2011.

                Comment

                Working...
                X