Raised This Month: $ Target: $400
 0% 

Method Map Constructors


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shortguy
Member
Join Date: Jul 2009
Old 01-04-2015 , 06:18   Method Map Constructors
Reply With Quote #1

How do I assign property values from inside a method maps constructor?

I want something that results in something like this (non functioning code):

Code:
methodmap Player {
	public Player() {
		this.Level = 0;
	}

	property int Level {
		public native get();
		public native set(int level);
	}
}

public OnPluginStart()
{
	Player myPlayer = Player();
	int level = myPlayer.Level;
}
It won't work for two reasons, I can't use this from inside the constructor, and the Level symbol is unassigned? I'm still new to this whole methodmap/quasi class object system, any tips?
shortguy is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-04-2015 , 16:55   Re: Method Map Constructors
Reply With Quote #2

Shouldn't you have an AskPluginLoad2 somewhere that declares the natives that actually back the Level property?
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
shortguy
Member
Join Date: Jul 2009
Old 01-04-2015 , 17:07   Re: Method Map Constructors
Reply With Quote #3

Sure, but that's not really relevant to the question is it?
shortguy is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 01-04-2015 , 17:21   Re: Method Map Constructors
Reply With Quote #4

Well, I think you can't store values in methodmap, only methods working with the variable itself (like get player healt, kick player, get player team etc).
KissLick is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-04-2015 , 17:30   Re: Method Map Constructors
Reply With Quote #5

Quote:
Originally Posted by shortguy View Post
Sure, but that's not really relevant to the question is it?
Quote:
Originally Posted by KissLick View Post
Well, I think you can't store values in methodmap, only methods working with the variable itself (like get player healt, kick player, get player team etc).
Exactly. I was under this same misapprehension and was corrected about it. You MUST have a backing plugin/extension for a methodmap.

In fact, I'm not even sure that would work for Plugins as you almost have to extend a methodmap from Handle (or something that inherits from Handle somewhere up the chain)... and the first argument for functions in MethodMaps has to be the type it ultimately inherits from (read: Handle).
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
shortguy
Member
Join Date: Jul 2009
Old 01-04-2015 , 17:32   Re: Method Map Constructors
Reply With Quote #6

Ah alright, thanks for clearing that up for me. It was a bit confusing when the lines between being an OOP class are pretty blurred with this new transitional syntax (I can't wait for the day of OOP driven SourceMod).

Thanks again.
shortguy is offline
BAILOPAN
Join Date: Jan 2004
Old 01-05-2015 , 00:30   Re: Method Map Constructors
Reply With Quote #7

For now it's best to think of methodmaps as a wrapper around functions that take a Handle.
__________________
egg
BAILOPAN 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 14:44.


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