Jump to content

Correct file structure


mehmet

Recommended Posts

Posted (edited)

 

Hi, 

I'm looking for an ideal structure for files.
If I keep all the scripts in one resource and compile all scripts into one file in server.lua and client.lua is this bad?

Edited by mehmet
  • Moderators
Posted

Yes, could be bad depending on your code style.

Because files are also code blocks. Which limit the accessibility of local variables.

 


Example, where it can go wrong:

 

File 1

local variableName = "can't be changed outside of this file"

function show ()
	iprint(variableName)  
end

 

File 2

variableName = "yes"

show () -- call the function show

 

It should output:

"can't be changed outside of this file"

Because the local variable can't be changed outside of it's scope.

 

 


 

Now put it in 1 file.

local variableName = "can't be changed outside of this file"

function show ()
	iprint(variableName)  
end

variableName = "yes"

show () -- call the function show

 

It should output:

"yes"

 

We have 1 file, 1 file scope. The `variableName` is available at the place where it is overwritten. (so the local variable will be overwritten)

 

 

  • Thanks 1
Posted
3 minutes ago, IIYAMA said:

Yes, could be bad depending on your code style.

Because files are also code blocks. Which limit the accessibility of local variables.

 


Example, where it can go wrong:

 

File 1


local variableName = "can't be changed outside of this file"

function show ()
	iprint(variableName)  
end

 

File 2


variableName = "yes"

show () -- call the function show

 

It should output:


"can't be changed outside of this file"

Because the local variable can't be changed outside of it's scope.

 

 


 

Now put it in 1 file.


local variableName = "can't be changed outside of this file"

function show ()
	iprint(variableName)  
end

variableName = "yes"

show () -- call the function show

 

It should output:


"yes"

 

We have 1 file, 1 file scope. The `variableName` is available at the place where it is overwritten. (so the local variable will be overwritten)

 

 

Thank's man. 
Can you show a good file structure?(screenshot)

  • Moderators
Posted

There isn't really a good file structure.

The real question is: "Does it work for you? If yes, then it might be a good file structure for you."

 

Posted
1 minute ago, IIYAMA said:

There isn't really a good file structure.

The real question is: "Does it work for you? If yes, then it might be a good file structure for you."

 

Well, which one do you use?
Posted

'Good' file structures differ from person to person one scripter may put everything in one script, one in one resource, another in multiple resources. It highly depends on preference. Performance wise, I believe multiple resources wins though.

  • Moderators
Posted
34 minutes ago, mehmet said:

Well, which one do you use?

Multiple resources and multiple files.

  • Every resource for every gamemode component. (hud, external interfaces)
  • And each file for sub tasks.

Sometimes it can be difficult to determine if you should split it up or not. Which can sometimes mean that it can actually be both.

When split it up? > If the tasks which the code full fill, are entirely different from each other.

 


 

As @CodyJ(L) did mention: performance

 

There are two types of performance showing up when doing this:

  • Computer performance.
  • Your own performance. (writing/reading code speed)

You will slowly learn how to keep those balanced, based on experience and inspiration. 

 

 

 

 

  • Thanks 1
Posted
10 hours ago, IIYAMA said:

Multiple resources and multiple files.

  • Every resource for every gamemode component. (hud, external interfaces)
  • And each file for sub tasks.

Sometimes it can be difficult to determine if you should split it up or not. Which can sometimes mean that it can actually be both.

When split it up? > If the tasks which the code full fill, are entirely different from each other.

 


 

As @CodyJ(L) did mention: performance

 

There are two types of performance showing up when doing this:

  • Computer performance.
  • Your own performance. (writing/reading code speed)

You will slowly learn how to keep those balanced, based on experience and inspiration. 

 

 

 

 

 


like that?
KvwxP

  • Moderators
Posted (edited)

Scoreboard isn't related to nametags. First-person isn't to both of them.

Hud might be related to scoreboard and yet it isn't.

So if you want to merge this in to a single resource. Then merge it in to the main gamemode. Because they aren't all huds (even though they might contain them).

 

And for the files:

/scripts/...

/fonts/...

 

 

Edited by IIYAMA

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...