Author Topic: A few questions about do_nut and referencing tables  (Read 1995 times)

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
A few questions about do_nut and referencing tables
« on: January 15, 2019, 06:01:59 AM »
Hey everyone.

Some relevant history: I used to live my life in Flash, particularly ActionScript, so most of my [limited] coding experience stems from that bygone era. I mention that because I'm having some trouble figuring out how to do a few things.

I have a .nut in which I'm placing a bunch of objects -- tables in Squirrel-speak, right? When I place the following in my layout.nut: fe.do_nut(filename.nut), which contains a few tables, if I try to access those tables later in my layout, I get a message saying they don't exist. Am I misunderstanding how do_nut works?

Second, in this external file (and I've tried in the main layout.nut, too), my objects (tables?) have names like rom_1942 or rom_bgaregga. What I'm trying to do is, on transition (that's another bag of fun I haven't figured out), combine the prefix rom_ with the results of fe.game_info(Info.Name) to access the equivalent table and its slots (e.g., rom_1942.btn1). Is there a way to reference a table when its name is composited like that? In javascript, I could do something like this:

Code: [Select]
var rom_1942 = { "btn1": "Fire", "btn2": "Loop" };

var pref = "rom_";
var romname = "1942";

console.log(window[pref + romname].btn1); // Outputs "Fire"

I'm partially thinking out loud here, and I don't have access to my AM machine right now...I guess my question about accessing indeterminate objects is what's the right way to access them? Could I use fe[pref + romname] and read its properties that way?

And since I'm here and rambling, are there any good, initially simple examples of how to get fe.add_transition_callback() to work? I've done something like this with no results:

Code: [Select]
function doStuff (ttype, var, ttime) {
    print ("ttype: " + ttype); // Never fires?
    return false;
}

...

fe.add_transition_callback(doStuff);

Clearly, I don't know what I'm doing. Thanks for any advice or insight!

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Re: A few questions about do_nut and referencing tables
« Reply #1 on: January 15, 2019, 05:40:57 PM »
All right, read the Squirrel docs a little more carefully and discovered I was attempting to assign "slots" (which I still think of as properties or attributes) the wrong way. Changing things up to something like the following seems to work:

Code: [Select]
this.rom_1942 <- { btn1 = "Fire", btn2 = "Loop };

Still have no idea about add_transition_callback :(

Wrapping my function name in quotes. That's what I was missing. Wow. Seems to be working now!
« Last Edit: January 16, 2019, 04:31:36 AM by Bgoulette »