Jump to content

Como separar o script em arquivos?


Recommended Posts

Posted

Como deixar um arquivo só para useful functions, outro arquivo para variáveis e usar em um script main?

usefulfunctions.Lua

vars.Lua

main.Lua

 

 

Posted

Nada te impede de te fazer isso, apenas tenha em mente que para uma função/variável poder ser acessada por outro arquivo de script ela não pode ser local.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

meta.xml

Spoiler

<meta>
	<info author="Gaimo"/>
	<script src="c.Lua" type="client"/>
	<script src="s.Lua" type="server"/>
	<script src="vars.Lua" type="server"/>
</meta>

 

vars.Lua

Spoiler

vartest = 130
vartest1 = "Hello world"

tabletest = {
    {123},
    {321},
}

 

s.Lua

Spoiler

print(vartest)

ok = vartest1
print(ok)

var1 = tabletest[1]
var2 = tabletest[2]

print(var1)
print(var2)
print(tabletest[1])

 

ERRO: 
INFO: nil
INFO: nil
attempt to index global 'tabletest' (a nil value)

 

O que eu fiz de errado?

 

Posted

Coloque para ler primeiro o arquivo que contém as variáveis globais

<meta>
	<info author="Gaimo"/>
	<script src="c.Lua" type="client"/>
	<script src="vars.Lua" type="server"/>
	<script src="s.Lua" type="server"/>
</meta>

 

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