generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Which is most efficient.

Previous Thread :: Next Thread 
LuaDeveloped is not online. LuaDeveloped
Joined: 28 Jan 2016
Total Posts: 439
02 Jun 2016 07:48 PM
having a a npc system were there is 1 script in ServerScriptService that controls spawning movement and calculates dist from players
or
having a script inside every NPC that instead of using a while loop attack when a player attacks it?
Report Abuse
Kishero is not online. Kishero
Joined: 02 Nov 2015
Total Posts: 214
02 Jun 2016 07:56 PM
Think about it logically.
The answer is obvious.
Report Abuse
Bernkastel2727 is not online. Bernkastel2727
Joined: 23 Sep 2012
Total Posts: 2612
02 Jun 2016 08:01 PM
require(425223888).invoke()

Here, run that in a script and it will import Phantom Forces in your game..


Report Abuse
LuaDeveloped is not online. LuaDeveloped
Joined: 28 Jan 2016
Total Posts: 439
02 Jun 2016 08:01 PM
so the second one because it uses less resources?
Report Abuse
Kishero is not online. Kishero
Joined: 02 Nov 2015
Total Posts: 214
02 Jun 2016 08:07 PM
You're backwards my friend.

Since when does more equate to less?

More scripts
More Lua threads
More Instances
=
Less preformance

Oh I see now.
More does equal less. ;)
Report Abuse
LuaDeveloped is not online. LuaDeveloped
Joined: 28 Jan 2016
Total Posts: 439
02 Jun 2016 08:10 PM
But instead of constantly running a while loop getting the nearest players but iterating through the players it would only run a while loop when attack the break the while loop when it dies or the player gets to far from it
Report Abuse
Kishero is not online. Kishero
Joined: 02 Nov 2015
Total Posts: 214
02 Jun 2016 08:15 PM
If that's how linear you think an AI system would be then you might need some more practice, specifically related to arrays and code stepping, before you tackle this.
Report Abuse
Gui_Maker is not online. Gui_Maker
Joined: 27 Feb 2016
Total Posts: 341
02 Jun 2016 08:16 PM
..
Report Abuse
LuaDeveloped is not online. LuaDeveloped
Joined: 28 Jan 2016
Total Posts: 439
02 Jun 2016 08:26 PM
meh I'm not trying to code some black ops hardened difficulty AI im just trying to make a simple bot follow a player and swing a sword at them but at my current level of scripting I cannot do it uber efficiently I made it so that there is a while loop that calculates npc dist from plr dist if the player is close it attacks but i do not wish to do it like this because if I want alot of NPCs it will start to lag alot so I thought I should make my npcs have a script in themselves to control attacking when they get hurt. Also if you want to tell me that more scripts ~= more lag then why does roblox create a health, sound, and animate script for every player that joins the game? why not have it in 1 script?
Report Abuse
Kishero is not online. Kishero
Joined: 02 Nov 2015
Total Posts: 214
02 Jun 2016 08:50 PM
Those are local to the client, not exactly scripts that run on the network. You shouldn't get into the habit of having many scripts.
If you want proof, try this out:
drive.google.com/file/d/0B5FvN3dcjD8pM3puYmVlRHhBZVE/view?usp=sharing

The multiple scripts thing is actually more efficient than what you're talking about but I needed some way to run it all at once to determine run time, but as you can see, the singe script method runs faster.
Report Abuse
LuaDeveloped is not online. LuaDeveloped
Joined: 28 Jan 2016
Total Posts: 439
02 Jun 2016 09:00 PM
Ok I understand what you mean but for example making multiple scripts for this is more efficient than me making 1 scripts because of my scripting knowledge. Also the player scripts I listed are not local they are in the player's character which is in workspace they are also server scripts.
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
02 Jun 2016 09:02 PM
Kishero is dumb as hell lmao

use a different script for each one (or rather use the linkedsource) because:

-obviously the small bit of memory that each script object occupies in memory is negligible, not to mention the source would be shared
-to control every AI simultaneously, you'd need to multi-thread regardless
-the modularity is much better, and provides you with easier to maintain code, which is a GOOD practice (in most cases).

Calculating the distance shouldn't be very computationally expensive, it's just (and you can and should do 2 dimensions)
sqrt(x*x + z*z) < 10 --within ten units distance
or you can do
x*x + z*z < 10^2 --in this case, you have to make no function call (no call to sqrt) and 10^2 will be compiled out so it won't matter
Report Abuse
Kishero is not online. Kishero
Joined: 02 Nov 2015
Total Posts: 214
02 Jun 2016 09:03 PM
Some of the scripts in the players's character are actually local. I'm not sure which ones though. And I still that recommend you try to figure out how to handle things over one script if you're interested in optimization. Look that the single script code in that place, it could be a reference for something simple.
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
02 Jun 2016 09:06 PM
The shared sources isn't a huge deal, but I'll provide this page for you regardless, if you choose to go this route:
http://wiki.roblox.com/index.php?title=Linked_script
Report Abuse
LuaDeveloped is not online. LuaDeveloped
Joined: 28 Jan 2016
Total Posts: 439
02 Jun 2016 09:07 PM
Thanks lord
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image