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

Method maps problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-20-2016 , 14:32   Method maps problem
Reply With Quote #1

Why I keep getting the "cannot find method or property Weapon.cost" every time I try to compile this ?
Code:
methodmap Weapon
{
        public Weapon(const char[] name, int cost)
        {
                // Things to do here
        }

        property int cost
	{
		public get() 
		{
			return this.cost;
		}
		
		public set(int value)
		{
			this.cost = value;
		}
	}
}
And how can I make a string property ? am I doing it correct here ?
Code:
        property char[] name
	{
		public get()
		{
			return this.name;
		}
		
		public set(const char[] name)
		{
			this.name = name;
		}
	}

        public int GetName(char[] name, int length)
	{
		return strcopy(name, length, this.name);
	}
	
	public void SetName(char[] name)
	{
		strcopy(this.name, sizeof this.name, name);
	}

Last edited by TheDS1337; 01-20-2016 at 14:41.
TheDS1337 is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 01-20-2016 , 14:44   Re: Method maps problem
Reply With Quote #2

Stuff like

PHP Code:
        public get() 
        {
            return 
this.cost;
        } 
is self-referential: this.cost calls get(), which references this.cost, which calls get(), and so on. Methodmaps are not actual classes and so they don't create new memory for a "cost" member variable; rather, you make the accessors reference some global variable or otherwise already existing memory, like

PHP Code:
int g_iCost;

...

        public 
get() 
        {
            return 
g_iCost;
        } 
Miu is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-20-2016 , 14:49   Re: Method maps problem
Reply With Quote #3

Oh, I think it's the wrong use of it I thought it works like classes or structs ...

EDIT: Can you give me an example with a string ?

is this correct ?

Code:
char g_weaponsName[][32];

........
        property int index
	{
		public get()
		{
			return view_as<int> (this);
		}
	}

        property char[] name
	{
		public get()
		{
			return g_weaponsName[this.index];
		}
		
		public set(const char[] name)
		{
			strcopy(g_weaponsName[this.index], sizeof g_weaponsName[], name);
		}
	}

        public int GetName(char[] name, int length)
	{
		return strcopy(name, length, this.name);
	}
	
	public void SetName(char[] name)
	{
		strcopy(this.name, sizeof this.name, name);
	}

Last edited by TheDS1337; 01-20-2016 at 15:08.
TheDS1337 is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 01-20-2016 , 15:24   Re: Method maps problem
Reply With Quote #4

You can't do

PHP Code:
char g_weaponsName[][32]; 
It needs to have a set size, like

PHP Code:
char g_weaponsName[8][32]; 
Other than that, I have no idea, I don't use methodmaps
Miu is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-20-2016 , 15:25   Re: Method maps problem
Reply With Quote #5

I want to it be a dynamic array of strings :/

Last edited by TheDS1337; 01-20-2016 at 15:33.
TheDS1337 is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 01-20-2016 , 15:32   Re: Method maps problem
Reply With Quote #6

Then you want ADT arrays: https://sm.alliedmods.net/api/index....oad=file&id=35
Miu is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-20-2016 , 15:34   Re: Method maps problem
Reply With Quote #7

Quote:
Originally Posted by Miu View Post
Okay, that's great, now I dont have to use the methodmap at all
TheDS1337 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 07:14.


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