View Single Post
nosoop
Veteran Member
Join Date: Aug 2014
Old 12-26-2015 , 11:15   Re: [TUT] Better Methodmaps tut
Reply With Quote #10

Quote:
Originally Posted by nergal View Post
I'm assuming you're saying that there's no real variables? They're just examples.
Here's what I (very sleepily) think might throw people off:
  • First example: The variable name index is vague. I'm assuming entity index based on context, but there's also array indices. MethodMap is also vague and I'd recommend replacing it with a more descriptive name for that particular example, like DamageableEntity.
  • Second example: I'd say add the constructor from the previous constructor to this snippet for completeness' sake, and explain that this basically just refers to the value passed into the constructor (which is why it was only returned with a different view; syntactic transformation only, remember!).
  • Third through fifth: Methodmaps have no member variables; just having iMoney, etc. show up out of nowhere leaves questions of implementation (which I can't think of a simple answer to except by saying "just pretend methodmaps don't exist and use some kind of array / data structure like you would've instead"). I'd point to the SourceMod transitional helpers for some examples of the "pass a variable and use 'wrapper' functions to manipulate them in a readable fashion", as well as the new API documentation for DataPacks (note: the x() = y binding was removed), StringMaps, etc. to show how they're used when you're working with Handles.
  • Eighth: int(x) doesn't exist in stock SourceMod?
Can't comment on __nullable__ as I'm not familiar with the specifics of that, but I'm sure they don't actually create objects (i.e., they won't magically have member variables).

Quote:
Originally Posted by Nerus View Post
OK, there is other method to create something similar to class?
Not quite natively. As mentioned, you have to store those "member" variables somewhere. The built-in StringMaps or Dynamic would work, but you'll be working with Handles at that point.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 12-26-2015 at 11:38. Reason: 8:30am? time for beeeeed
nosoop is offline