Drakath Posted February 15, 2015 Share Posted February 15, 2015 local lPlayer = localPlayer What is more efficient? 1. Use lPlayer over 10 times 2. Use localPlayer 10 times? Link to comment
JR10 Posted February 15, 2015 Share Posted February 15, 2015 Practically the same thing, just use localPlayer since it's predefined and everyone knows it. Numbers, strings, booleans and nil are passed by value, you basically have 2 variables that are equal but do not affect each other. It's fine if you don't get what I mean here, you can read more about it here: http://www.lua.org/manual/5.1/manual.html#2.2 Link to comment
Gallardo9944 Posted February 15, 2015 Share Posted February 15, 2015 I always do something like local LOCALPLAYER = localPlayer just because my text editor highlights uppercase variables with bold black colour. I don't think there is any other use of that. Link to comment
Drakath Posted February 15, 2015 Author Share Posted February 15, 2015 But I mean if I use the local lPlayer, system will store it and use the memory. If I use localPlayer, system will check for local player and use CPU. Am I right? Link to comment
JR10 Posted February 15, 2015 Share Posted February 15, 2015 No. When the script starts localPlayer is a 'userdata' that points to the local player. When you define lPlayer, it's now a 'userdata' variable that points to the local player. Before localPlayer variable was predefined, most people did this at the start of their client scripts: localPlayer = getLocalPlayer() See, the "system" doesn't need to check for the local player, as the local player will never change. Client scripts run on the client, so localPlayer doesn't change, there's no "looking" involved. Link to comment
Drakath Posted February 15, 2015 Author Share Posted February 15, 2015 I see, thanks. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now