Categories > Coding > Lua >

How to write a basic "Hello World!" script

PoopMaster

SoundInfinity

noticed

Posts: 120

Threads: 23

Joined: Jul, 2019

Reputation: 9

Posted

In programming, it's essential that you know how to code a program that outputs "hello world". This thread will talk about how to accomplish it, and will explain the steps to do it.

 

First off, you would need to understand that print is classified as a "function", and the main use of functions is to prevent repeating code.

 

A function has parameters and takes arguments, the number of parameters and arguments are not limited,  although, having way too many would not be good for readibility, and therefore not recommended.

A function can also return, or better said "say something back", whenever it wants unless its execution is done.

 

Also, parameters are essentially variables that are stored locally in the function. Wait, what do you mean by "locally"? There are two types of variables in Lua, locals and globals.

 

Local variables are only accessible on their code block. But, globals are accessible by the whole script. By accessible, I mean they either can be read or set.

 

In Lua, accessing a local variable is faster than accessing a global one.

 

To write a simple function, use the following format:

[code]

-- "sum" is the name of the function

function sum(a, b) -- Code block starts

print(a + b) -- Adds parameters "a" and "b" together.

end -- Code block ends

 

sum(1, 2) -- Sends arguments 1 and 2

[/code]

 

The function "print" can take many arguments, and of any type, for example: functions, strings, tables, etc. The type that I'm going to use is a string, a string is basically just text between quotation marks (e.g: "this is a string"). Now, let's see what a hello world program looks like.

 

[code]

print("Hello World!")

[/code]

 

And yeah, that's about it. I'm not good at explaining stuff, so plz don't bully me.

  • 0

Proud creator of: WRD+

Posts: 0

Threads: 0

Joined: ?

Reputation:

Replied

 

293 words 1,714 characters just for an explanation of a print script

BRUH lol

nice thread br0

 

  • 0

classiccat

#becomeacat

vip

Posts: 421

Threads: 1

Joined: Aug, 2019

Reputation: -46

Replied

[code]

print("i learned how to print!")

[/code]

  • 0

...

Posts: 351

Threads: 109

Joined: Mar, 2018

Reputation: 37

Replied

wrd+ losing :/

  • 0

‏‏‏‏‏

Hectique

Hectique

Posts: 1079

Threads: 155

Joined: Nov, 2019

Reputation: 14

Replied

[/code]

print("For the 4 year olds")

[/code]

  • 0

a former active and known member of the WRD community, but im kinda just a meme now

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )