Announcement

Collapse
No announcement yet.

From ini file, to flash (Another inventory thread)

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

    From ini file, to flash (Another inventory thread)

    Hey, I'm trying to get an inventory working using Scaleform. (Like I see alot of other people have done/are trying to do)

    I'm using the Sapitu system to save a character and his items into a config ini file. Which makes them come out like this in the ini file:

    Code:
    [elmuerte SapituCharacter]
    CharacterName=elmuerte
    CharacterClass=UDK Game Maker
    Health=100
    maxHealth=100
    mana=0
    maxMana=0
    Gold=0
    Level=1
    Strength=5
    dexterity=5
    magic=10
    defense=5
    inventoryRecords=book1_001_
    inventoryRecords=sword1_002_
    
    [book1_001_ SapituInventory]
    ItemName=book1
    quality=100
    Level=30
    characterLevel=1452998656
    Weight=4
    Value=17
    
    [sword1_002_ SapituInventory]
    ItemName=sword1
    quality=100
    Level=6
    characterLevel=0
    Weight=13
    Value=11
    I'm just wondering what would be the best way to read all the items the character has and get the data into scaleform via an array or something so I can show the items on the hud. And how I'd go about doing it.

    Sorry for creating another thread about this sorta thing, but I've been looking around for a while now and nothing has helped me so far.

    So basicly I need to be able to import that data into scaleform.

    #2
    Okay I think I'm really close.

    Here is a function in flash to change a frame:

    Code:
    function inventoryItems(slotNum:Number, item:String):Void {
        inventory_mc["slot"+slotNum].gotoAndPlay(item);
    }
    This works perfectly fine if I call the function and pass the values within flash itself.

    but if I try to use this:

    Code:
    function showInventory()
    {
    		
    		local int i;
    		local ASValue RetVal;
    		local array<ASValue> Parms;
    	for (i = 0; i < char.inventory.Length; ++i)
    	{
    		Parms[0].Type = AS_Number;
    		Parms[0].n = i;
    
    		Parms[1].Type = AS_String;
    		Parms[1].s = String(char.inventory[i].item.Name);
    		Invoke("inventoryItems", Parms);
    	}
    	`log("[STGFxHUD].[hideInventory] begins");
    	ActionScriptVoid("showInventory");
    	`log("[STGFxHUD].[hideInventory] begins");
    }
    To pass the values from unreal to scaleform, it doesn't work it all, am I passing the values into the function using invoke incorrectly ?

    Comment


      #3
      Code:
      local ASValue asval;
      local array<ASValue> Parms;
      
      asval.Type = AS_Number;
      asval.n = someFloat;
      Parms[0] = asval;
      Invoke("inventoryItems", Parms);

      Comment


        #4
        I still can't get it working, probably getting something completely wrong.

        So here is my function for it now
        Code:
        	for (i = 0; i < char.inventory.Length; ++i)
        	{
        		asval.Type = AS_Number;
        		asval.n = Float(i);
        		Parms[0] = asval;
        		asval.Type = AS_String;
        		asval.s = String(char.inventory[i].item.Name);
        		Parms[1] = asval;
        		Invoke("inventoryItems", Parms);
        	}
        So my character has only one item on him at the moment, with the name of 'sword1'.

        so the above code should make this command happen in actionscript, correct?
        Code:
        inventoryItems(0, "sword1");

        Comment


          #5
          Scratch anything I asked above, this will probably be easier to answer and is more what I want.

          I'm using the InventoryDemo.fla. I'm just wondering how I'd go about populating
          Code:
          var itemData:Object = [
          	{type:"armor",asset:2},
          	{type:"weapon",asset:3},
          	{type:"spell",asset:4},
          	{type:"spell",asset:5},
          	{type:"wand",asset:6},
          	{type:"spell",asset:7,quantity:7},
          	{type:"spell",asset:8},
          	{type:"spell",asset:9,quantity:3}
          ];
          with all the details from my char.inventory.

          Comment


            #6
            Try using something like this:

            UnrealScript


            Code:
            /** Item struct */
            struct Items
            {
                var string ItemName;
                var string ItemType;
                var string ItemDesc;
            };
            
            var array<Items> Inventory;
            
            function SetUpInventory()
            {
                local byte i;
                local GFxObject DataProvider;
                local GFxObject TempObj;
                local GFxObject RootMC;
            	
                RootMC = GetVariableObject("_root");
            
                DataProvider = CreateArray();
            	
                for (i = 0; i < Inventory.Length; i++)
                {        
            	TempObj = CreateObject("Object");
            	TempObj.SetString("ItemName", Inventory[i].ItemName);
            	TempObj.SetString("ItemType", Inventory[i].ItemType);
            	TempObj.SetString("ItemDesc", Inventory[i].ItemDesc);
            	DataProvider.SetElementObject(i, TempObj);
                }
            
                RootMC.SetObject("inventory", DataProvider);  	
                ShowInventory();
            }
            
            function ShowInventory()
            {
                ActionScriptVoid("showInventory");
            }

            ActionScript 2.0 Code

            Code:
            var inventory:Array = [];
            
            function showInventory()
            {
                for (i:Number = 0; i < inventory.length; i++)
                {
            	trace("Name: " + inventory[i].ItemName + " | Type: " + inventory[i].ItemType + " | Description: " + inventory[i].ItemDesc);
                }
            }
            Getting the Data from Flash

            UnrealScript

            Code:
            function ListInventory()
            {
                local GFxObject Item;
            
                // Method 1
                // These lines return the name, type, and description of the inventory item stored at element 0 of the inventory[] array in the Flash file.
                `log("Item Name: " @ RootMC.GetObject("inventory").GetElementMemberString(0, "ItemName"));
                `log("Item Type: " @ RootMC.GetObject("inventory").GetElementMemberString(0, "ItemType"));
                `log("Item Description: " @ RootMC.GetObject("inventory").GetElementMemberString(0, "ItemDesc"));
            	
                // Method 2
                // This version first caches a reference to the GFxObject{} found at element 0 of the inventory[] array.
                Item = RootMC.GetObject("inventory").GetElementObject(0);
            
                `log("Item Name: " @ Item.GetString("ItemName"));
                `log("Item Type: " @ Item.GetString("ItemType"));
                `log("Item Description: " @ Item.GetString("ItemDesc"));
            }

            Comment


              #7
              Sorry to go a bit off the tread but since im working on someting similar Whats the best way to get a reference of what item the player has click on?

              Basicly im triying to access the object or well the item the player cursor is above of and Well pretty much that

              Comment


                #8
                That depends on your setup. I need more information to be able to offer any pointers.

                Comment


                  #9
                  Had a go at implementing this, think I'm getting it completely wrong. I'm quite tired at the moment, so I might sleep, have a go at it again and the post how I've gone with it.

                  Just one question though, I've got 'I' set to do the command showInventory, if I make the new setUpInventory command should I set 'I' to this? Because I tried this and it doesn't load showInventory from it.

                  Comment


                    #10
                    Originally posted by Matt Doyle View Post
                    That depends on your setup. I need more information to be able to offer any pointers.
                    Well i got a ScrollingList that populates with the player inventory Items So lets say there are 2 Buttons Equip and Drop If the plaer selects a Item from its inventory and then click on Equip I need to acess to that item Properties (Ini File that has the item properties) And make a check to see if the item can be equipped

                    Basicly I only need to get the Properties of the item the player has click on from the scrollingList im not sure if i expressed properly ...

                    Comment


                      #11
                      Rhiyo: Sorry. Maybe I'm not being clear. I haven't given you an implementation that fits into your code perfectly. I've given you an example of how to send the data to Flash. How you incorporate it into your code base is going to take some modification by you.

                      Comment


                        #12
                        alvarofer0021:

                        In your WidgetInitialized() function, include a case for your ScrollingList like so:

                        Code:
                        case ('sl'): // or whatever the instance name of your ScrollingList is.
                            ScrollingList = GFxClikWidget(Widget);
                            SetUpDataProvider(ScrollingList);
                            ScrollingList.AddEventListener('CLIK_itemPress', onItemPress);
                        Then add this function to figure out which item was pressed.

                        Code:
                        function onItemPress(GFxClikWidget.EventData ev) 
                        {
                            itemIndex = ev.index;
                            `log("Item Selected Index: " @ ev.index);
                        }
                        Now that you have the index #, you can use it to compare it to an array that contains all the current inventory items. The index should match the array element (index 2 = element 2, etc.). Each element of the array will hold an object containing all the item data (name, item type, description, etc.). Items should be pushed onto this array as they are picked up.

                        For instance, if you stored all the items the player has in his inventory in an array called Inventory[]:

                        Code:
                        struct Items
                        {
                            var string ItemName;
                            var string ItemType;
                            var string ItemDesc;
                        };
                        
                        var array<Items> Inventory;
                        
                        var Name ItemName;
                        var Type ItemType;
                        var Desc ItemDesc;
                        
                        function onItemPress(GFxClikWidget.EventData ev) 
                        {
                            ItemName = Name(Inventory[ev.index].ItemName);
                            ItemType = Name(Inventory[ev.index].ItemType);
                            ItemDesc = Name(Inventory[ev.index].ItemDesc);
                            `log("Item Name: " @ ItemName @ " | Item Type: " @ ItemType @ " | Item Desc: " @ ItemDesc);
                        }

                        Comment


                          #13
                          Awesome! it was easier than what i tough Thanks again Matt

                          Comment


                            #14
                            I've modified it, I've probably just modified it completely wrong. Heh.

                            I'll show you my class that extends off of GFxMoviePlayer.

                            Code:
                            class STGFxHUD extends GFxMoviePlayer;
                            
                            //Current character
                            var SapituCharacter char;
                            
                            //Create a Health Cache variable
                            var float LastHealthpc;
                            
                            //Create variables to hold references to the Flash MovieClips and Text Fields that will be modified
                            var GFxObject HealthTF, Crosshair;
                            
                            var DogPlayerController PlayerOwner;
                            
                            struct Items
                            {
                                var string ItemName;
                                var string ItemType;
                                var string ItemDesc;
                            };
                            
                            var array<Items> Inventory;
                            
                            //Called from STHUD'd PostBeginPlay()
                            function Init2(DogPlayerController PC)
                            {
                            	//Start and load the SWF Movie
                            	Start();
                            	Advance(0.f);
                            
                            	//Load the references with pointers to the movieClips and text fields in the .swf
                            	HealthTF = GetVariableObject("_root.healthbar_mc.health_txt");
                            	HealthTF.SetString("text", string(char.health)$"/"$string(char.maxHealth));
                            	Crosshair = GetVariableObject("_root.crosshair_mc");
                            }
                            
                            //Called every update Tick
                            function TickHUD()
                            {
                            	local UTPawn UTP;
                            
                            	//We need to talk to the Pawn, so create a reference and check the Pawn exists
                            	UTP = UTPawn(PlayerOwner.Pawn);
                            	if (UTP == None)
                            	{
                            		return;
                            	}
                            	SetUpInventory();
                            	HealthTF.SetString("text", string(char.health)$"//"$string(char.maxHealth));	
                            }
                            
                            function SetUpInventory()
                            {
                                local byte i;
                                local GFxObject DataProvider;
                                local GFxObject TempObj;
                                local GFxObject RootMC;
                            	
                                RootMC = GetVariableObject("_root");
                            
                                DataProvider = CreateArray();
                            	
                                for (i = 0; i < char.inventory.Length; i++)
                                {        
                            	TempObj = CreateObject("Object");
                            	TempObj.SetString("ItemName", char.inventory[i].item.DisplayName);
                            	TempObj.SetString("ItemType", char.inventory[i].item.DisplayName);
                            	TempObj.SetString("ItemDesc", char.inventory[i].item.DisplayName); (They all say DisplayName because this is one of the only data for the item that exists at the moment)
                            	DataProvider.SetElementObject(i, TempObj);
                                }
                            
                                RootMC.SetObject("inventory", DataProvider);  	
                                showInventory();
                            }
                            
                            function showInventory()
                            {
                            		
                            	`log("[STGFxHUD].[hideInventory] begins");
                            	ActionScriptVoid("showInventory");
                            	`log("[STGFxHUD].[hideInventory] begins");
                            }
                            
                            function hideInventory()
                            {
                            	`log("[STGFxHUD].[hideInventory] begins");
                            	ActionScriptVoid("hideInventory");
                            	`log("[STGFxHUD].[hideInventory] begins");
                            }
                            
                            DefaultProperties
                            {
                            	//this is the HUD. If the HUD is off, then this should be off
                            	bDisplayWithHudOff=false
                            	//The path to the swf asset we will create later
                            	MovieInfo=SwfMovie'SFDogRPG.HUD.ScaleformHUD'
                            }
                            And my hud class that execs it (SetUpInventory is executed through 'I')

                            Code:
                            class DogHUD extends MobileHUD;
                            
                            //Reference the actual SWF container (STGFxHUD created later)
                            var STGFxHUD HudMovie;
                            var bool bIsInventoryOpen;
                            
                            //Called when this is destroyed
                            singular event Destroyed()
                            {
                            	if (HudMovie != none)
                            	{
                            		//Get rid of the memory usage of HudMovie
                            		HudMovie.Close(true);
                            		HudMovie = none;
                            	}
                            	//super.Destroy();
                            }
                            
                            //Called after game loaded - initialise things
                            simulated function PostBeginPlay()
                            {
                            	super.PostBeginPlay();
                            
                            	//Create a STGFxHUD for HudMovie
                            	HudMovie = new class'STGFxHUD';
                            	//Set the HudMovie's PlayerOwner
                            	HudMovie.PlayerOwner = DogPlayerController(PlayerOwner);
                            	//Set the timing mode to TM_Real - otherwise things get paused in menus
                            	HudMovie.SetTimingMode(TM_Real);
                            	//Call HudMovie's Initialise function
                            	HudMovie.Init2(HudMovie.PlayerOwner);
                            	HudMovie.hideInventory();
                            }
                            
                            exec function SetUpInventory()
                            {
                            	`log("[PlacementHUD].[showInventory] begins");
                            	HudMovie.SetUpInventory();
                            	bIsInventoryOpen = true;
                            	`log("[PlacementHUD].[showInventory] ends");
                            }
                            
                            exec function hideInventory()
                            {
                            	`log("[PlacementHUD].[hideInventory] begins");
                            	HudMovie.hideInventory();
                            	bIsInventoryOpen = false;
                            	`log("[PlacementHUD].[hideInventory] ends");
                            }
                            
                            //Called every tick the HUD should be updated
                            event PostRender()
                            {
                            	HudMovie.TickHUD();
                            }
                            and the related code in the flashes actionscript

                            Code:
                            var inventory:Array = [];
                            	
                            	
                            function showInventory()
                            {
                            	panel._alpha = 100;
                            	charpanel._alpha = 100;
                            	cursor_mc._alpha = 100;
                            	
                            	    for (i:Number = 0; i < inventory.length; i++)
                                {
                            	testtext.text = ("Name: " + inventory[i].ItemName + " | Type: " + inventory[i].ItemType + " | Description: " + inventory[i].ItemDesc); (This is just to test if any data is being put through into the hud)
                                }
                            }
                            I think it's most likely that it isn't getting any character details from var SapituCharacter char; in STGFxHUD (Is there anyway I can test this within STGFxHUD, I see other commands that log things but have no idea where this log is.)

                            I load a character using a console command, and this character has one item in his inventory, I havn't showed any of the character classes yet because that would be to much, and I should probably go to the unrealscript section for that.

                            Comment


                              #15
                              Your code looks fine. Although I probably wouldn't run the SetupInventory() function every tick. I'd only run it when the player picks up an item.


                              To use the game log, launch the game with -log. In your UnrealScript use:

                              `log("blah" @ somevariablename);

                              etc.

                              For Flash, use:

                              trace("blah" + somevariablename);

                              To see Flash trace statements in the log:

                              Open UDKEngine.ini
                              Find the line: Suppress=DevGFxUI
                              Comment it out by adding a semi-colon in front of it.

                              Use some log & trace statements to see what's going on. Make sure you're not getting compile errors when you publish your Flash files too, and no Accessed None errors in Unreal when you run the game. (You'll see these in the log window).

                              Comment

                              Working...
                              X