Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

silktie

Retaining a variable when entering a Cave

Recommended Posts

Mobbstar    14123

I considered string.dump too, but although I had never had to use it for anything before, I did notice while screwing around that it output an unreadable string, so I assumed that this was also binary bytecode.  After checking with the documentation(just now), it says:

Them pesky upvalues :(

Damn I had issues with upvalues already, errors about them are the indication of crude madhacking!

I had a little bit of time to test just now, and I'm next to positive that what I described is happening.  You should be able to easily recreate this test I did:

Here's the pertinent section of modmain.lua for reference:

Part 1:

Create two potions (specifically, a wormlight and an empty alchemypotion).  Drink 1 to verify that it works.  Save and quit game.  Reload the save.  Now when you try to drink the remaining potion, you'll get this error:

Here's that line:

(SpawnPrefab is imported as a local in modmain's context at the top of the file, outside of the drinkfn)

Part 2:

 

Edit line 514 of modmain.lua to be the following:

Reload the save.  Discard the potion from Part 1.  Since its stale references persist, it'll always cause an error.  Create a new potion using a wormlight and an alchemypotion.  Save and quit game.  Reload the save. Try drinking potion.  You'll get this new error:

Oh, that seems like the kind of issue that was bound to occur when copy-pasting code and blindly assuming "no crash = works well"

Well that got us past the SpawnPrefab hurdle, but unfortunately it looks like there's another stale reference (or some other error) once it it gets to line 522 and calls ResumeSpell().  I haven't tested this, though it would be pretty easy to... but my guess is that it's caused by the preceding statement at 521:

Looks like I forgot to refer to the args table...

 

val is another upvalue, this time coming from the class constructor.  I imagine(but haven't tested) that since the upvalue is on the right side of an assignment operator, nil is getting assigned to duration.  Later when I have some time I'll check if the error still occurs when assigning a numeric literal to duration.

 

Part 3: (just to confirm that the functions really are getting stored as compiled bytecode)

Modify the code of the drinkfn so that it's guaranteed to raise an error before any other problems arise.  Ex:

Load game.  Brew one last wormlight potion. Save and quit.  Before loading the saved game, modify the intentionally erroring code to something innocuous.  Blank spaces work just fine:

 

Load saved game.  Drink potion.  Error as expected:

 

Edit:

 

If it was a strongly typed language, 9.2.  Since it's Lua... ehhhhh... I'm gonna go with 7.5.  It's still a very Rube-Goldbergian way of going about it, lol.

Hehe, that's way too forgiving. Wait what's a typed language? Typed text is how humans write in any language. And Lua doesn't even get compiled beforehand, so following that "logic" it'd be the most typed language among them all!

 

Interesting, I didn't know the game is smart enough to make up for sloppy coding :p

 

I'll rewrite the mod, so I'll not (use classes excessively or) end up saving the same functions over and over again anyways hopefully maybe I think we'll see.

 

Thank you for the insight and advice!

(Gonna see about that saving module later, Blueberrys)

Share this post


Link to post
Share on other sites
Blueberrys    172
Hehe, that's way too forgiving. Wait what's a typed language? Typed text is how humans write in any language. And Lua doesn't even get compiled beforehand, so following that "logic" it'd be the most typed language among them all!

"Strongly typed". "type" meaning variable types such as integer, string, float, etc. Not typing with a keyboard. (Simpler explanation)

Share this post


Link to post
Share on other sites
Corrosive    163

@Mobbstar

I feel like it's my civic duty if you're rewriting the mod to mention that it's spelled "distiller" (unless the alternate spelling was inebriated)

I think "destiller" is what happens when movie execs realize that the budget for Zoolander 2 is far too big.

 

edit: typos courtesy of Swype

Share this post


Link to post
Share on other sites
Corrosive    163

@Blueberrys,

 

Oh great now I'm going to be self conscious about how I use the phrase "strongly typed" ;)

 

I guess "platform or language that strongly enforces type-security / compile-time type checking" would be more accurate <.<

 

 

 

....but screw that noise :D

Share this post


Link to post
Share on other sites
Blueberrys    172

@Corrosive I think you used the term fine, but it's such a vague and undefined term that it can be confusing. It's probably better to keep it reserved for humorous or non-educational kinda things (as above).

 

We're so off topic, btw. This thread is for variables in caves.

 

@Mobbstar I think you might as well start a new topic regarding your mod. I'd like to help out with it when I have some time.

Share this post


Link to post
Share on other sites