Raised This Month: $51 Target: $400
 12% 

Static property in methodmap


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Godis
Senior Member
Join Date: Jan 2014
Old 12-19-2015 , 10:40   Static property in methodmap
Reply With Quote #1

Hello. I've been using static methods for my natives instead of normal functions, sort of like namespaces in other languages. I do know this is not how methodmaps are supposed to be used but it makes it much easier to distinguish what belongs to where, for example;

FooBar.Get(); instead of GetCurrentFooBar();

So my question: Is this possible?

PHP Code:
FooBar.Value 10;
PrintToChatAll("%i"FooBar.Value); 
I've tried but i can't seem to make my property static, and i really don't want to do this:

PHP Code:
FooBar foo;
foo.Value 10
I'm not a native english speaker so forgive me if i've used incorrect terms.
Godis is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 12-20-2015 , 16:06   Re: Static property in methodmap
Reply With Quote #2

if it is "static", don't create the setter and return the value wanted on the get.

get() = { return 10; }

EDIT:

Or if u were looking the other way arround.

int myVar = 0;

FooBar.set(int value) = { myVar = value; }
FooBar.get() = { return myVar; }

no matter how many foobar you use they will refer to the same variable value.

Last edited by Mathias.; 12-20-2015 at 18:51.
Mathias. is offline
Godis
Senior Member
Join Date: Jan 2014
Old 12-21-2015 , 09:19   Re: Static property in methodmap
Reply With Quote #3

Okay so what i want is not FooBar.Get()/FooBar.Set(int value), i want to have multiple values i can retrieve/set with FooBar.Value = 1/FooBar.Value, just like ConVar.IntValue works. But after trying many different things it seems like it can't be done currently so i'll have to go with FooBar.Get/FooBar.Set for the time being.

Last edited by Godis; 12-21-2015 at 09:19.
Godis is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 12-21-2015 , 16:20   Re: Static property in methodmap
Reply With Quote #4

I'm confuse of what your trying to do. I don't see the "static" mimic at all in what your trying to do.

posibility that I understand:
#1
if you think you have to call FooBar.Get() or FooBar.Set() is because you do not understand methodmaps properties.

You have to use FooBar.Value = 1 and FooBar.Value it just you have to declare inside your methodmap what will happen getter/setter.

PHP Code:
int g_iGlobalMimicStaticHolder;

methodmap FooBar
{
    
property int Value 
    
{
        public 
set(int value) { g_iGlobalMimicStaticHolder value };
        public 
get() { return g_iGlobalMimicStaticHolder; }
    }
}

Some where in code:
FooBar foo;
foo.Value 2;

FooBar myNewFoo;
if (
foo.Value == myNewFoo.Value)
    
PrintToServer("it work!"); 
#2
If you want to save value per instance of object then you have to store it some where. Example of unlimited storage:
PHP Code:
ArrayList g_MyValue;

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint error_length)
{
    
g_MyValue = new ArrayList(1);
    
    
/* if use natives put it there */
    
return APLRes_Success;
}

methodmap FooBar
{
    public 
FooBar()
    {
        return 
view_as<FooBar>g_MyValue.Push(0/* default variable value here */); 
    }
    
    
property int Index
    
{
        public 
get() { return view_as<int>this; } // array index
    
}

    
property int Value 
    
{
        public 
set(int value) { g_MyValue.Set(view_as<int>thisvalue); }
        public 
get() { return g_MyValue.Get(view_as<int>this); }
    }

You can also declare your methodmaps function as native if you want to share w.e. memory with other plugins
property int Value
{
public native set();
...
inside AskPluginLoad2
CreateNative("FooBar.Value.set", Native_SetFooBarValue);
...

well that pretty much it

Edit: none of the above has been really tested but the logic should be right and the examples prob work just don't be suprise if I mistype a var or w.e.

Last edited by Mathias.; 12-21-2015 at 18:58.
Mathias. 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 12:28.


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