Jump to content




Code Blocks (in Lua) And Local Variables


  • You cannot reply to this topic
4 replies to this topic

#1 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 24 October 2013 - 08:29 PM

I saw a bunch of scattered definitions of code blocks and local variables over the tutorials section, so I decided to put my own here.

Definition Of Blocks
Making Blocks
Local Variables

This is all I had time to write tonight, make sure to leave (constructive) criticism on the tutorial! MUCH more content and details will be coming soon1.

Sources: http://www.lua.org/pil/4.2.html, Personal Experience

1 Soon is not guaranteed to be any particular time...

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 24 October 2013 - 09:58 PM

Needs a lot of work but I think it has potential. You've also missed quite a lot of code blocks. Also think about fixing and/or defining your high-level terms such as scope.

#3 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 24 October 2013 - 10:56 PM

View Posttheoriginalbit, on 24 October 2013 - 09:58 PM, said:

Needs a lot of work but I think it has potential. You've also missed quite a lot of code blocks. Also think about fixing and/or defining your high-level terms such as scope.

Thanks. I had limited time to post it, so that's the reason it lacks most content.

What are these other blocks you speak of?

I'll work on it A LOT when I have time.

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 25 October 2013 - 01:36 AM

Honestly I think you should have typed up the tutorial in a text editor and only posted it when you had more time to finish it off and make it better.

Any control statement is a block. When you leave the control statement any local variables defined within are deallocated.

Code blocks

Quote

function [name]([arguments]) [statements] end // function
if [condition] then [statements] end // if statement
while [condition] do [statements] end // while
for [declaration], [limit], [increment] do [statements] end // numeric for
for [declaration] in [iterable] do [statements] end // generic for
do [statements] end // do block
repeat [statements] until [condition] // repeat


#5 surferpup

  • Members
  • 286 posts
  • LocationUnited States

Posted 21 January 2014 - 02:12 PM

The only thing I note is that technically a doend is not technically a control structure. Control structures can redirect the sequential nature of the program counter inherently. Even a simple ifthenend control structure can cause the program to jump to the end of the control structure, skipping any code blocks contained within. All of the looping control structures (while, repeat and for) have dramatic impact on the program counter. doend specifically identifies a code block, in fact it is the only way to explicitly declare a code block without the use of a control structure.

I think I cover this pretty thoroughly in Lua Basics -- Variable Scope, Code Blocks and Control Structures.

Edited by surferpup, 21 January 2014 - 02:13 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users