Page 1 of 1

Some noob questions

Posted: Mon Feb 20, 2017 10:39 am
by NoAim91
Hello, I try since several hours and i don´t get it, so i´m sorry for this simple questions but i can´t figure out how to do it.

1.) I have a function with some if statements, and at the last if statement i like to set a global variable from true to false. I know how to change is in the local, but how do i get the scope to global? (i have tryed return, but it doesn´t work)

2.) How to call a function? Sounds stupid, i know .. but at the end of the if statement it should say to a function "do your thing" without give any value input.

Re: Some noob questions

Posted: Mon Feb 20, 2017 3:53 pm
by Zireael
1) the same way you set a local variable, just without the local keyword
2) DoYourThing() (capitalization is entirely optional) - however you need to have the DoYourThing() function defined beforehand

Re: Some noob questions

Posted: Mon Feb 20, 2017 8:20 pm
by NoAim91
thanks for the reply ... like every time my problem was something other. But I solved it.

But I have a new Question :-)

What GUI should i use? Should i write my own at the very beginning?

edit: is there any good GUI Tutorial für lua (and probebly löve?)

Re: Some noob questions

Posted: Mon Feb 20, 2017 9:45 pm
by Positive07
I recommend SUIT or Gööi, or if you dare, binary ones like imgui or nuklear

Re: Some noob questions

Posted: Tue Feb 21, 2017 9:36 am
by NoAim91
Thank you SUIT looks fine :-)

another question ... when/why I use " : " in lua?

Re: Some noob questions

Posted: Tue Feb 21, 2017 10:22 am
by zorg
You can use it wherever you want (it's just syntactic sugar); more importantly, here's the shortest way (for me) to show how it differs from dot notation:

Code: Select all

local t = {}
function t.f(a,b) return self,a,b end
function t:g(a,b) return self,a,b end
t.f(1,2) --> nil, 1, 2
t:f(1,2) --> nil, t, 1
t.g(1,2) --> 1, 2, nil
t:g(1,2) --> t, 1, 2

Re: Some noob questions

Posted: Tue Feb 21, 2017 10:46 am
by Positive07
This

Code: Select all

local t = {}

function t.func (self, a, b, ...)
   print(self) --Prints t
   --Code
end

Is equivalent to this

Code: Select all

local t = {}

function t:func (a, b, ...)
   print(self) --Prints t
   --Code
end

And this

Code: Select all

t.func(t, 1, 2, 3)
Is equivalent to this

Code: Select all

t:func(1, 2, 3)