7 replies [Last post]
Joined: 08/05/2015
Groups: None

I am just starting writing scripts for Foldit. I have no experience of Lua, but I have been a professional programmer for many years, so my status is "noob with insight". In my first script, I want to print out contactMap data. I have copied and pasted the functions from http://foldit.wikia.com/wiki/Foldit_Lua_Functions. The error I get is:

*** attempt to index global 'contactmap' (a nil value) ***

Here is my code:

segmentCount = get_segment_count()
print ("Segment count: " .. segmentCount)

for source = 1, segmentCount do
  for target = source + 1, segmentCount do
    inContact = contactmap.IsContact(source, target)
    heat = contactmap.GetHeat(source, target)
    print("Segments "..source..", ".. target..": in contact = "..inContact..", heat = "..heat)
  end
end

Thanks in advance for any enlightenment.

Brian

Joined: 04/20/2012
Groups: Go Science
LUA V1 or V2 ?

Instead of this line (which I think is for LUA V1):
segmentCount = get_segment_count()

I would use this line (which I think is for LUA V2):
segmentCount = structure.GetCount()

Using an editor with line numbers helps decipher the error messages Foldit gives.
On what line number did the error occur? What is the code on that line?

Also, I'd like for Recipes that do similar things and imitate or adapt their code.
This is a good way to learn the syntax for various LUA and Foldit functions.

Joined: 04/20/2012
Groups: Go Science
See if this recipe gives any insight:

I'd look for recipes like the following and see if their code gives any insight.

Band All Contacts Adaptive v2.2
http://fold.it/portal/recipe/101238

Joined: 04/20/2012
Groups: Go Science
Did you redefine contactmap?

Maybe somewhere else in your code you used a line like:

contactmap={}

so that contactmap is now a local variable instead of a Foldit command.

Joined: 08/05/2015
Groups: None
My code is exactly what you

My code is exactly what you see in my initial message. Nowhere do I redefine contactmap. If I change the first line to...

segmentCount = structure.GetCount()

... then I get the error

*** attempt to index global 'structure' (a nil value) ***

This would imply either that:

  • My script has no access to the global objects, and that I need to declare them before I use them
  • The version of foldit that I downloaded three days ago is not version 2, and does not know anything about these global objects

Is there a way of displaying the current version of foldit?

Joined: 08/05/2015
Groups: None
The problem is that I had

The problem is that I had originally loaded a V1 script and made changes to that.

I looked at Band All Contacts Adaptive v2.2 and did a slash and burn to get to the script that I had first imagined:

-- segmentCount = get_segment_count() -- now causes an error
segmentCount = structure.GetCount()
print ("Segment count: " .. segmentCount)

for source = 1, segmentCount do
  for target = source + 1, segmentCount do
    inContact = contactmap.IsContact(source, target)
    heat = contactmap.GetHeat(source, target)
    print("Segments "..source..", ".. target..": heat = "..heat)
  end
end

This runs fine, with no errors, because the original script that I was modifying was already V2.

Joined: 09/24/2012
Groups: Go Science
Indeed

On the top of the Editor's windows, the version of Lua is written (V1 or V2). A V1 script does not recognize V2 commands and reverse. Any "new" recipe will now be edited in V2. If you want to script in V1, you have to take an old V1 recipe and "save as " it to your new one with V1 commands. To code in V2, simply open a new window in the editor.

Susume's picture
User offline. Last seen 1 hour 25 min ago. Offline
Joined: 10/02/2011
The currently available Lua

The currently available Lua functions in foldit can be found at http://foldit.wikia.com/wiki/Foldit_Lua_Functions

Sitemap

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, RosettaCommons