Is this change possible with our level of access?
Soul_Rider
Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
I am looking to edit the base component structure. I would like to create code that will implicitly allow a get(variable) and set("variable", value) command on any variable created in a component. I want to do this to save the time of writing a get and set function multiple times in every component and script I write
Is it possible to do this in lua, or would/should this be an engine level change?
I haven't seen any exposed code relating to components directly, so assume this would need to be done at an engine level. If so, would it be possible to make such a change?
As an example, a team_number component has the following code:
With an implicit get() and set() on every member variable the code for this component becomes simply:
This would be a great help to me and save a valuable amount of time if it could be implemented, or if I could be pointed to somewhere where I can implement it, either would be good
Is it possible to do this in lua, or would/should this be an engine level change?
I haven't seen any exposed code relating to components directly, so assume this would need to be done at an engine level. If so, would it be possible to make such a change?
As an example, a team_number component has the following code:
--- number (0,8) local teamNumber = 0 local function SetTeamNumber(setTeamNumber) teamNumber = setTeamNumber end function OnNewTeamNumber(message) if message.teamnumber >= 0 and <= 8 SetTeamNumber(message.teamnumber) end function GetTeamNumber() return teamNumber end
With an implicit get() and set() on every member variable the code for this component becomes simply:
--- number (0,8) local teamNumber = 0 function OnNewTeamNumber(message) if message.teamnumber >= 0 and <= 8 set("teamNumber", message.teamnumber) end
This would be a great help to me and save a valuable amount of time if it could be implemented, or if I could be pointed to somewhere where I can implement it, either would be good
Comments
The main reason to use getters/setters is to create an abstraction between the implementation and the code that's using the implementation. This allows the the implementation to change without affecting the other code. In our scripting model, that abstraction already exists in the form of the message handler.
You may want the same abstraction within a script. For example, if you set the team number from a bunch of different locations within the script. In this particular case you might also want to do the validation that the team number is between 0 and 8 every time you set it, so it makes sense to create a SetTeamNumber function to handle that. This can be done on a case-by-case basis though. And in this particular case, there's no real reason to use a getter.
While I definitely wouldn't recommend this, as a point of curiosity, the answer to your original question is that it could be done something like this:
I am still trying to see why messaging works better than calling get or set methods? The component is still separate, and you are still needing to update/retrieve the information. As a relative low-end programmer, I can't see how they differ, except messages seem to throw out data for anyone to read.
I do see a for loop, or at least I think I do
What max tried to explain for example was that ther is no need for setters and getters in lua as in java. I'm not any good in lua but there are things called tables and they perform pretty much how soul_rider wants to interact with variables.
Essentially, the logics of writing a program don't change, just the words used to do them.
Lua is very simple to understand because the the keywords are quite obvious - If, for, while, do, and, true, false, etc.
The way my brain works personally, learning one language, but looking at and trying to interpret another, always helps me further my code understanding.
I am still a fairly low end programmer, but I can read a lot of code that I couldn't yet even dream of writing, and can read code reasonably well in multiple languages. Some of those languages I wouldn't even attempt to code in currently though.
These 10% are in no way more or less intelligent than the others, their brains are just wired that way. For example people who have 0 affinity for programming can be geniouses in biology or chemistry.
The important thing when learning to code is to understand the general concept. Its not just syntax, languages consist of syntax, grammar and semantics. The fact that you can read lots of code but not write it may mean that you dont understand the code. I can also read a spanish newspaper and have no idea what it's about.
Especially in Java, there are things like object orientation which are inherent to get a grasp of the language LUA handles this very differently (apparently through the abovementioned tables) and mixing these two concepts up will not do you very much good.
And your comment is the most ridiculous thing I have ever heard.
If you do not understand the spanish, you are not reading it. Reading requires Comprehension....
Or can I just flick through the pages of a Hebrew book for example, without understanding any of it and claim to have read it, which is what you are claiming.
Look, I don't know why you think my comments are anything to do with you. The last one was not, this one is a direct reply to you as you mentioned me. But I have already given up having a conversation with you, as you are a person who is always right, as you showed in the other thread.
Personally, I don't want to spend my time having a discussion with someone who is always right, because I don't learn anything, and nor do they..
So if you understand, my replies before and after you in a topic are not aimed at you unless I specifically name you, you can forget I exist and stop thinking about me. I was doing a great job of ignoring you on the forums until you mentioned me above. You really are not that important in my life, and I really generally couldn't care about what you post.
If you'll do me the same courtesy and just leave me alone, unless you genuinely have something useful to contribute, that would be great.
Your answer of "hey I can learn multiple languages at once" seemed to me like a mockery to my advice for ezekel. I don't know if you can program and I don't know how you may have learned it but I know that it is a really tough piece of work for some people. I frequent a programming board from time to time and there are tons of beginners asking questions because the learn the language in the wrong way.
When you say reading requires comprehension, I say take a technical text in a field you have no idea what it is about (try reading the latest bills of your government). You will be able to perfectly read it out loud, understand each and every word but you wont know what it is about, at least until you read it a few times - that's the semantics. When you said you can read any code but you are not able to write that code you read I assumed this is a similar situation.
Finally, if you dont want to spend time with my posts, don't reply to them. I did not attack you in any form, there is no reason to be so defensive.