Back to Recipes Homepage
recipe picture
Recipe: ScriptV2 Recipe Basics
Created by GaryForbis 60 2065
Your rating: None Average: 5 (3 votes)


Name: ScriptV2 Recipe Basics
ID: 100039
Created on: Thu, 10/02/2014 - 06:40
Updated on: Sun, 10/26/2014 - 04:46

Version 0.5. Learn the ScriptV2 Recipe language basics. This Recipe has a series of lessons to help you learn the language so you can read and modify existing recipes and write your own. Learn by doing.

Best For


Joined: 04/11/2013
Thank You Gary

A Big Big Thanks

Joined: 08/06/2010
Groups: Contenders
One the entanglement of comments and string literals.

String literals and comments interact with each other in strange ways. Try this code:

print 'something ]] print "strange ' -- happening "
-- [[
print 'something ]] print "strange ' -- happening "

I'll try to explain this better in a future release. Normal people don't write code like that intentionally but mistakes happen. The notion of levels of long comments and strings is a bit strange at first. They provide better control over temporary or disabled code. They also provide an easy way to control what appears in a string.

Joined: 09/24/2012
Groups: Go Science
Thanks !

It's instructing from the beginning, and enjoyable.

(my only problem is that I cannot type "[" within the editor, I don't know why).

May be explaining to the users that they may cut- paste (Ctrl x Ctrl V) to a text editor, then edit, then come back to the recipe editor (Ctrl A Ctrl C Ctrl v)

That's how I edit recipes, personally using Notepad++ where I can select "Lua2" language in order to clearly see coloured comments, statements etc.

The advantage of such a text editor for debugging is that it shows the line number (useful for debugging).

Joined: 08/06/2010
Groups: Contenders
thanks, that's lesson 6, parting thoughts.

I figured by the end people would be tired of the foldit editor and were ready to use notepad++

Do you think I should make that lesson 2 instead?

Joined: 09/24/2012
Groups: Go Science
It depends

Whriting in the foldit editor is better for the user (it's quite simple to jump from the editor to the recipe and come back, after some time, we do it quick).

But as I cannot type "[" in the editor, neither select and copy it in order to paste it, I suppose I'm not the only one. But frankly said, I don't find very important to type the multiple level comments back. Possible solutions:

1) May be you can simply delete the suggestion to type them back when the exercise is done?

2) Indeed, making the editor problem lesson 2 is a solution. But it's quite heavy and discouraging to be obliged to download something in order to learn further.

3) or say this possible problem in a note in lesson 2, and preparing it since lesson 1, something like:

In lesson 1, when explaining how to save the personal copy of the recipe, suggest to save as "ScriptV2 Recipe Basics-Your Name -Lesson1" and do the same for each lesson.

and add a note in lesson 2:

"Note: the Foldit editor is limited - If you experience problems typing special characters like "[" from your national keyboard, type this character to an external text editor and copy-paste it here or just don't type it back. You can also always recover the latest recipe you saved, like the version saved in lesson 1. I'll explain much more convenient ways for editing recipes in lesson 6 (using free script editors).

btw, I'll right a feedback to Foldit team on the Foldit editor.

Joined: 08/06/2010
Groups: Contenders
about not being able to type [ in the foldit editor

Thanks again for the feedback.

I change long comments into short comments by putting a space between the dashes and the brackets.

--[[ this is a long comment

-- [[ these are two short comments

the point of putting the two dashes in front of the ]] is so one doesn't have to touch that line when enabling the code. I find it easier to add a space between the -- and [[ rather than delete the [[.
That's definitely true when dealing with higher level long comments.

--[===[ wow I need to fix this code


-- [===[ wow I need to fix this code

lets one remember what it took to disable the code where deleting the brackets (and equal signs) does not. One could even write this:

-- enable this code temporarily --[===[ wow I need to fix this code

I definitely need to explain this better.

Here's some more interesting examples:

---[[ this is a short comment because the third character is a dash.
--[ this is a short comment because the second [ is missing.

You don't need to type the [ back in if you don't remove it.
Do you know why you can't type the bracket in the foldit editor?
Are you using it as a hot key or does your keyboard require a special set of keystrokes to produce it?

I definitely want to discuss ways around this in my script, including the possibility of finding text somewhere else and pasting it into one's program at the cursor. The intent is to keep the changes simple so one doesn't need to use notepad++ or some other editor to learn lua.

Your feedback is definitely quite valuable.

Joined: 09/24/2012
Groups: Go Science

Thanks ! I'm still learning further.
And it's a good solution (even for me scripting)

To type ] or any other character I mentioned, I need, on my "Belgian Dutch" azerty keyboard, to push Alt Gr+ the key.

For example, on key $, I have:
key= $
Shift + key = *
Alt gr + key = ]

Same problem for all characters needing Alt Gr on the Foldit editor (and on chat of course).

A picture of this kind of keyboard is here:

Joined: 09/24/2012
Groups: Go Science
even worst

I have also a Mac with the following keyboard:

There, I even do not know how to type the characters mentioned above (I don't see them on the keyboard).

But I found them by trying with alt and alt+shift ...

alt+( = {
alt+shift+( =[

but of course, this works here but it doesn't work in the Foldit editor.

Joined: 09/24/2012
Groups: Go Science
small bug

I have abug when the recipe prints something like:

print (This, 'isn't equal to ',that)

just because of the use of '

Is it by purpose? I corrected them by using "

print (This, "isn't equal to ",that)

Joined: 08/06/2010
Groups: Contenders
OK, is this the bug

print ('6 is of type,type(6))
print ('"6" is of type,type("6"))

should have been:

print ('6 is of type',type(6))
print ('"6" is of type',type("6"))

I was having a hard time making sure I fixed the bugs in the right place. I would do some editing in the foldit editor then repeat the changes in notepad++. I should follow my own advise and save the working copy in a different named recipe then only update the original when I'm completely done. Developing the code while protecting the user experience of it was more trouble than I had expected.

I'll fix the error and release a new version. It wasn't on purpose. I only intended one bug and I said it existed.

I'm hoping people will introduce their own errors as they modify the code and can look at the output knowing their errors are in the code they changed.

Joined: 09/24/2012
Groups: Go Science

it's line 418 of the new recipe
and 445
On Lesson 4, I read :
?tableconstructor :: = ? etc. Is it normal that "?" is written there in this section?


replace detial by detail


I find the recipe fine for "learning by doing". The way to present exercises is nice ! We can play with main functions and see what they do.
It's quick done (I did it in 2 times about 1 hour) and efficient.
May be you could copy-paste the latest part (lesson 6) here in the comments of the recipes?

Personally, I have the most difficulties with tables. The difference between pairs and ipairs, the way to print multidimensional tables etc (tables like in excel with more than 1 columns).

Thanks !

Joined: 08/06/2010
Groups: Contenders
what I find at lines 413 through 422

--[[ The or operator
print (type(x)) -- type is a predefined function
print ("x or 'x is not assigned a value' is",x or 'x is not assigned a value')
x = x or 'x is assigned a value'
print ("x or 'x is not assigned a value' is",x or 'x is not assigned a value')
x = x or "x is assigned a value if one wasn't already assigned"
print ("x or 'x is not assigned a value' is",x or 'x is not assigned a value')
print ("x or nil is",x or nil)
print (type(x))

line 418 has been modified because it had:
x = x or 'x is assigned a value if one wasn't already assigned'

that won't work because of the contraction.

The output as captured from scriptlog.default.xml is:

x or 'x is not assigned a value' is x is not assigned a value
x or 'x is not assigned a value' is x is assigned a value
x or 'x is not assigned a value' is x is assigned a value
x or nil is x is assigned a value

thus showing that x retains its original non nil value.

lesson 4 spelling error fixed.

I am working on an improved explanation of the for and while loops and multidimensional tables.
By Monday I will release the next version with these and better distinction between pairs and ipairs.

Joined: 09/24/2012
Groups: Go Science
another small bug in lesson 3 (students can debug themselve !)

replace ipair by ipairs

Joined: 08/06/2010
Groups: Contenders
arg, another unintended bug.

Thanks. I have released a new version with these bugs fixed.

Let me know if there are areas I could improve.
Also, please suggest any areas I should cover but didn't.

Joined: 08/06/2010
Groups: Contenders
Version 0.5 released

It fixes the issues mentioned.
I have added a bit more depth in a couple of areas.

robgee's picture
User offline. Last seen 2 hours 36 min ago. Offline
Joined: 07/26/2013
Very nice

Very informative, it will take me a while to digest.

Want to try?
Add to Cookbook!
To download recipes to your cookbook, you need to have the game client running.





Developed by: UW Center for Game Science, UW Institute for Protein Design, Northeastern University, Vanderbilt University Meiler Lab, UC Davis
Supported by: DARPA, NSF, NIH, HHMI, Amazon, Microsoft, Adobe, Boehringer Ingelheim, RosettaCommons