Welcome aboard Visitor...

Daily Screenshot

Server Costs Target


0% of target met.

Latest Topics

- I will no longer be hosting this server »
- Anyone still playing from a decade ago or longer? »
- Game still active. NICE! »
- help me »
- Password resett »
- Darkspace Idea/Opinion Submission Thread »
- Rank Bug maybe? »
- Next patch .... »
- Nobody will remember me...but. »
- 22 years...asking for help from one community to another »

Development Blog

- Roadmap »
- Hello strangers, it’s been a while... »
- State of DarkSpace Development »
- Potential planetary interdictor changes! »
- The Silent Cartographer »

Combat Kills

Combat kills in last 24 hours:
No kills today... yet.

Upcoming Events

- Weekly DarkSpace
11/02/24 +1.8 Days

Search

Anniversaries

23th - Starfleet.
8th - Cyber999

Social Media

Why not join us on Discord for a chat, or follow us on Twitter or Facebook for more information and fan updates?

Network

DarkSpace
DarkSpace - Beta
Palestar

[FAQ
Forum Index » » Basic Scripting Discussion » » [INFO] LUA training exercises
 Author [INFO] LUA training exercises
Chromix
Cadet

Joined: June 29, 2001
Posts: 3052
Posted: 2003-04-03 10:02   
Some things you can script in LUA to see if you understood the manual.
Note that all these tasks can be done completely without darkspace, you just need the lua.exe and luac.exe.
There is most times not just one solution but multiple ways to solve it.

Please don't post your solutions here.
These tasks are very basic ones. So if you've problems solving them then don't try to get the solutions from someone else - it won't help you. You're usually on your own with the more advanced stuff. So you should solve these basic tasks on your own too.

Write a script which:
1) Outputs this text:
Finished 10% of the "test".

2) Prints all numbers from 1 to 99, one per line.

3) Prints all numbers from 99 to 1, two per line.

4) Print all numbers from 1 to 99 which are dividable by 3.

5) Write a function which returns a table (Lua-table, not some output which looks like a table on the screen) which holds the numbers 32 to 126 as index, and the corresponding ASCII char as value.

6) Write a function which prints that Lua-table ( number, value pairs ), 5 per row.

7) Modify the function so it handles tables of any size if you didn't so already.
Meaning you could give the function a Lua-table with the index range 65 to 77 (without giving the function that values / storing them in global variables before).

8) Modify the function so it takes an additional variable which allows to set the number of number/ascii pairs per line.

9) Write a function which takes two numbers as input parameters and returns (return as in lua-return, not printing) both multiplied as result. Try "test" and 4 as input parameters. Prevent the error from occuring and make the function return nil in case of such an error.

Bonus (Try this only if you want to)
10) Solve 9) without using these statements: "if", "while", "repeat".

Btw: The point is that you don't just solve these few simple tasks. You should play around with a few things, test them to get familiar with Lua.

Here is an article on code formatting, choosing names for variables etc.
http://www.devshed.com/c/a/Practices/Writing-Quality-Software-A-Primer/2/
It's not for Lua, but that doesn't matter as the content is quite generic. Especially pages 3 to 5 are interesting.


[ This Message was edited by: Chromix on 2009-10-11 02:37 ]
_________________


  Email Chromix
Chromix
Cadet

Joined: June 29, 2001
Posts: 3052
Posted: 2004-03-05 13:05   
Another problem here.
This isn't some "annoying test" to pass. It's preparation for more advanced things you'll have to deal with later on.
It allows you to see for yourself if you're ready for that. An essential point is that you figure out things on your own. It's important because there'll be lots of other things you'll have to figure out on your own later on.
If you aren't able to solve these exercises on your own, you also won't be able to write any useful DS scripts on your own too.

So, try not to get too much "help" from others.

I just felt like writing this because I got identical solutions from different users multiple times now.
And to keep the motivation for "cheating" through this little test down:
It's not like "pass the test and get access to the adv. forum / ds-scripts immediately". You'll just get some more non-public exercises afterwards, so you can demonstrate you are ready.

[edit] No more extra tests before you get access. The adv. forum is now readable to everyone.

[ This Message was edited by: Chromix on 2009-10-11 02:39 ]
_________________


  Email Chromix
Page created in 0.007482 seconds.


Copyright © 2000 - 2024 Palestar Inc. All rights reserved worldwide.
Terms of use - DarkSpace is a Registered Trademark of PALESTAR