Raised This Month: $32 Target: $400
 8% 

Dynamic Objects and Properties - v.0.0.32 - [2018.05.08]


Post New Thread Reply   
 
Thread Tools Display Modes
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-03-2016 , 20:36   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #121

Dynamic represents an index integer where as collection represents a Handle.

The two methodmaps cant be converted via view_as.

You should get/set ClientFeatureList with the Handle type and view_as Collection.

PHP Code:
    property Collection ClientFeatureList
    
{
        public 
get()
        {
            static 
int offset INVALID_DYNAMIC_OFFSET;
            if (
offset == INVALID_DYNAMIC_OFFSET)
            {
                
offset this.GetMemberOffset("ClientFeatureList");
                if (
offset == INVALID_DYNAMIC_OFFSET)
                {
                    
SetFailState("A serious error occured in Dynamic!");
                }
            }
            return 
view_as<Collection>(this.GetHandleByOffset(offset));
        }
        public 
set(Collection value)
        {
            static 
int offset INVALID_DYNAMIC_OFFSET;
            if (
offset == INVALID_DYNAMIC_OFFSET)
            {
                
offset this.GetMemberOffset("ClientFeatureList");
                if (
offset == INVALID_DYNAMIC_OFFSET)
                {
                    
offset this.SetHandle("ClientFeatureList"value);
                    return;
                }
            }
            
this.SetHandleByOffset(offsetvalue);
        }
    } 
__________________

Last edited by Neuro Toxin; 09-03-2016 at 21:17.
Neuro Toxin is offline
Dark Athena
Member
Join Date: May 2016
Old 09-04-2016 , 19:53   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #122

Okay thank you for your help I have one last question : D. is it possible to have an array as a type?
Dark Athena is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-04-2016 , 19:57   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #123

Standard arrays are not supported.

Your best to use an ArrayList.
__________________
Neuro Toxin is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 09-08-2016 , 16:23   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #124

For example, I have this:

Code:
public TimerSettings LoadStyles()
{
	Dynamic dStylesConfig = Dynamic();

	// i know the path to sourcemod can be different because of '+sm_basepath', just testing
	if(!dStylesConfig.ReadKeyValues("addons/sourcemod/configs/shavit-styles.cfg"))
	{
		return INVALID_TIMERSETTINGS;
	}

	if(dStylesConfig.MemberCount == 0)
	{
		dStylesConfig.Dispose();

		return INVALID_TIMERSETTINGS;
	}

	else
	{
		PrintToServer("count: %d", dStylesConfig.MemberCount);
	}

	dStylesConfig.Dispose();

	TimerSettings tsStyles = TimerSettings();

	/*if(tsStyles.GetInt("amount") == 0)
	{
		return INVALID_TIMERSETTINGS;
	}*/

	return tsStyles;
}
The keyvalues file looks like that:
Code:
"Styles"
{
	"0"
	{
		"name"	"Normal"
	}

	"1"
	{
		"name"	"Sideways"
	}
}
dStylesConfig.MemberCount equals to 1 (I assume, that's because "Styles" is the main key), but dStylesConfig.GetObject("Styles") is also invalid, what's wrong? How would I access and iterate between subkeys?
__________________
retired
shavit is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-08-2016 , 19:17   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #125

I would expect dStylesConfig.GetName to return "Styles" and for it to contain 2 dynamic members.

There might be a bug after the recent refactors.

Can you use WriteKeyValues to another file and check the data structure isn't malformed / corrupted?
__________________
Neuro Toxin is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 09-09-2016 , 02:12   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #126

Quote:
Originally Posted by Neuro Toxin View Post
I would expect dStylesConfig.GetName to return "Styles" and for it to contain 2 dynamic members.

There might be a bug after the recent refactors.

Can you use WriteKeyValues to another file and check the data structure isn't malformed / corrupted?
dStylesConfig.GetName returned "" and contained 1 member.

I wrote this test code:
Code:
#include <sourcemod>
#include <dynamic>

public void OnPluginStart()
{
	Dynamic dStylesConfig = Dynamic();
	dStylesConfig.SetName("Styles");

	Dynamic dNormal = Dynamic();
	dNormal.SetName("0");
	dNormal.SetString("name", "Normal");
	dNormal.SetInt("airaccelerate", 1000);
	dStylesConfig.PushDynamic(dNormal);

	Dynamic dSideways = Dynamic();
	dSideways.SetName("1");
	dSideways.SetString("name", "Sideways");
	dSideways.SetInt("airaccelerate", 1000);
	dStylesConfig.PushDynamic(dSideways);

	char[] sPath = new char[PLATFORM_MAX_PATH];
	BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "configs/shavit-dynamic.cfg");

	if(!dStylesConfig.WriteKeyValues(sPath))
	{
		PrintToServer("Could not write keyvalues!");
	}

	dStylesConfig.Dispose(true);
}
This is the output keyvalues file:
Code:
""
{
	"name"	"Normal"
	"airaccelerate"	"1000"
}
""
{
	"name"	"Sideways"
	"airaccelerate"	"1000"
}
No "Styles" main key, no names for subkeys
__________________
retired
shavit is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-09-2016 , 02:37   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #127

Its malformed. Ill fix it up tomorrow for you. Thanks for yhe test!
__________________
Neuro Toxin is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 09-09-2016 , 03:01   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #128

Quote:
Originally Posted by Neuro Toxin View Post
Its malformed. Ill fix it up tomorrow for you. Thanks for yhe test!
np, i appreciate the development of dynamic
__________________
retired
shavit is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-09-2016 , 05:37   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #129

Thanks for the feedback!
__________________
Neuro Toxin is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-10-2016 , 01:28   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #130

I've just pushed an update for KeyValues.

Code:
"Styles"
{
    "0"
    {
        "name"    "Normal"
    }

    "1"
    {
        "name"    "Sideways"
    }
}
The below example would get "Normal".
Code:
dynamic.ReadKeyValues(...);
dynamic.GetDynamicByIndex(0).GetString("name", ...);
__________________
Neuro Toxin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode