Jump to content

Using entity name as variable

Lord Henry

Recommended Posts

  • Other Languages Moderators


Is there any difference between using the entity's name instead of a custom name in a variable?

local vehicle = createVehicle (...)


local theVehicle = createVehicle (...)

Why does the Wiki always avoid using the entity's name as variable?
If I use the entity's name instead of a custom name, is this a bad programming method?

PS: I am not using OOP.

Link to comment
  • Moderators

If you did use OOP, then you would be overwriting the MTA classes.




It should be fine as long as you do not use OOP or overwrite predefined variables. https://wiki.multitheftauto.com/wiki/Predefined_variables_list

Be aware that other people who do use OOP and want/need to edit your resource will be having a hard time.


So no worries, just but be consistent in your code.

Link to comment
  • Discord Moderators

No, he would't overwrite any of the classes, since class names are always UpperCamalCase, and not camalCase.
But, as @IIYAMA (man, I writing ur name down is so f*cking hard) said, you be consistent in your code.
And, because I see you put effort in your work, I'll write down a few tips:

  1. Be as consistent with your style ap(as possible)
  2. Variables are always camalCase, classes are UpperCamalCase, and constants are either UPPERCASE or UPPER_CASE, try to use tables with constants which have the same purpose(like so: 
    local ANIM_SETTINGS = {
      speed = 1,
      eastingFunction = "Linear",
    instead of: 
    local ANIM_EASTING_FUNCTION = "Linear"
    local ANIM_SPEED = 1
  3.  Try to ask google first, and not someone else, because asking Google is much faster.
  4. Try to use OOP, instead of PP, because OOP is more readable.
  5. If you use OOP, then try to organize functions by classes, like. (So instead of: setWeather() have a class like: Weather.set())
  6. Premature optimization is the root of all evil
  7. Use ternary operations as much as possible, because 'if' statements are ugly, and slow. (Sure, don't do what I do sometimes(I tend to rewrite a whole if statement to a ternary operation))
  8. Try to be as descriptive ap in var names, so instead of TYPE(of animation) do ANIM_TYPE. Because TYPE can be really anything.

I hope I helped you :)

Edited by Pirulax
Link to comment
  • Moderators
59 minutes ago, Lord Henry said:

Any answer?

Yes, more than enough.  And if you want to be 100% sure, you can check the wiki logs and find the person that wrote the comment + ask him/her yourself.


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...