Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 28 29 [30] 31 32 ... 42

Author Topic: [DFHack] Roses' Script Collection Updated 5/4/15  (Read 120088 times)

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #435 on: December 05, 2014, 04:01:22 pm »

Yes, it has the new system. I do have a slight concern with it: there's no versioning information so it may eventually not be forward-compatible anymore. At some point I want to store the version of the persistent table system itself in the save somewhere the first time you use it or ask for it so that if I change the way things work it can automatically convert stored data. It currently does not do this but it will probably be an easy fix to just store a version number and worry about the details later.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #436 on: December 05, 2014, 04:56:03 pm »

Perfect, but that shouldn't affect my tests at all right? And just for clarification, everything needs to be stored as strings, correct?
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #437 on: December 05, 2014, 05:06:00 pm »

Perfect, but that shouldn't affect my tests at all right? And just for clarification, everything needs to be stored as strings, correct?

Quick test says either tables or strings, yeah, no numbers. Apparently tostring('1'+2) evaluates as '3' in Lua, though, so that's convenient.

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #438 on: December 05, 2014, 05:11:40 pm »

Hahaha, I thought I remembered expwnent saying something about that earlier, so if you look at my code you will see quite a bit of tostring and tonumber (probably more than is needed, but I was sort of distracted while writing it and in some places I just wanted to make explicitely clear that something needs to be a number or a string). Interestingly lua understand that "7" + 3 = 10, but I didn't want to rely on that so I used tonumber.

And for you Putnam, most of my variables have been renamed so that they actually represent what they are! No more ddtot and dds everywhere!

EDIT: Do either of you know how I could run a script whenever a new unit comes on the screen?

EDIT2: Decided to add another feature to the classes, they can now get permanent buffs for leveling (as I mentioned in the previous post). For now it will be a static increase, that is to say it will be the same for each level. The syntax will be [LEVEL_BONUS:PHYSICAL:attribute:amount]. Then whenever the unit levels up in that class they will gain a bonus to the specified attribute. These bonuses will not be lost after switching to another class, unlike the current bonuses provided from [BONUS_PHYS] etc...
« Last Edit: December 05, 2014, 08:28:52 pm by Roses »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #439 on: December 05, 2014, 10:24:37 pm »

I made a UNIT_SPAWN event for Fantastic a while ago, but it was iffy as hell.

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #440 on: December 06, 2014, 09:36:38 pm »

Perfect, but that shouldn't affect my tests at all right? And just for clarification, everything needs to be stored as strings, correct?

Yes, it should not affect testing and it is strings only for table names and table values.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #441 on: December 07, 2014, 02:41:42 am »

So I'm running into a little problem, when I try and do this
Code: [Select]
persistTable.GlobalTable.roses = persistTable.GlobalTable.roses or {}
I get this
Code: [Select]
[lua]# persistTable.GlobalTable.roses = persistTable.GlobalTable.roses or {}
C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:121: stack overflow
stack traceback:
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:121: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        ...
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:124: in functio
n 'deletePersistent'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\persist-table.lua:172: in functio
n '__newindex'
        (interactive):1: in main chunk
        [C]: in function 'safecall'
        C:\Users\Miles\Desktop\My_DF2\hack\lua\dfhack.lua:366: in function 'inte
rpreter'
        C:\Users\Miles\Desktop\My_DF2\hack\scripts/lua.lua:47: in main chunk
        (...tail calls...)
Logged

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #442 on: December 07, 2014, 03:18:15 am »

Strange. When I try that it doesn't crash, even when I do it twice in a row to make sure that it exists. Can you give any more details?
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #443 on: December 07, 2014, 03:25:22 am »

Hmm, i think it's happening because I already have persistTable.GlobalTable.roses.ClassTable defined, and it isn't liking that... Could that be it?
Logged

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #444 on: December 07, 2014, 03:31:47 am »

I'm getting a different error.

Code: [Select]
-- load game with no persistent data
persist.GlobalTable.foo = {}
persist.GlobalTable.foo.asdf = {}
persist.GlobalTable.foo.asdf.asdf1 = '1'
persist.GlobalTable.foo.asdf.asdf2 = '2'
persist.GlobalTable.foo = persist.GlobalTable.foo or {}
-- save, reload
persist.GlobalTable.foo = persist.GlobalTable.foo or {}
--error: persist-table.releasesym(0): available.value = 0
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #445 on: December 07, 2014, 04:01:11 am »

So it appears that when my scripts get run more than once they create exponentially larger tables. And that that is causing an overflow issue. For some reason it is setting up the tables as persistTable.GlobalTable.roses.UnitTable.UnitTable.UnitTable.UnitTable.UnitTable etc... I don't know what's going on...
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #446 on: December 07, 2014, 04:09:52 am »

I am so glad I decided to learn metatables a while ago, heh.

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #447 on: December 07, 2014, 04:13:56 am »

So it appears that when my scripts get run more than once they create exponentially larger tables. And that that is causing an overflow issue. For some reason it is setting up the tables as persistTable.GlobalTable.roses.UnitTable.UnitTable.UnitTable.UnitTable.UnitTable etc... I don't know what's going on...

Hmm. That's very bad. I'll have to take a look at that.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #448 on: December 07, 2014, 04:42:35 am »

It could be because I am doing something terribly wrong, but I don't really see what. This is the first part of the two scripts that I added to make the persist-table work... Something I am doing wrong?

Code: (classes.lua) [Select]
local persistTable = require 'persist-table'
persistTable.GlobalTable.roses = persistTable.GlobalTable.roses or {}
persistTable.GlobalTable.roses.UnitTable = persistTable.GlobalTable.roses.UnitTable or {}

local split = require('split')
local events = require "plugins.eventful"
events.enableEvent(events.eventType.UNIT_DEATH,100)
local filename = dfhack.getDFPath().."/raw/objects/classes.txt"
local establishclass = require('classes.establish-class')
local read_file = require('classes.read-file')

Code: (read-file.lua) [Select]
local split = require('split')
local utils = require 'utils'
local persistTable = require 'persist-table'
persistTable.GlobalTable.roses.ClassTable = persistTable.GlobalTable.roses.ClassTable or {}
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] Roses' Script Collection
« Reply #449 on: December 07, 2014, 04:53:06 am »

Maybe try using "x=x~=nil and x or y" instead of "x=x or y".
Pages: 1 ... 28 29 [30] 31 32 ... 42