How to remove Lua script error?

  • HappyDog
    1st Jan 2021 Member 0 Permalink

    When I start lua script use console command, console write: ????.lua:1: unexpected symbol near "%"

    How to repair script? I can send script for analysis.

  • TiredTech
    1st Jan 2021 Member 0 Permalink

    I might be able to help, but I suggest posting such a question in ThePowderToy/LuaScripting forum next time. You might just be using the dofile command wrong. If your script is called Script1.lua then you would run it with dofile ("Script1.lua")  If your file were called Pizza.lua then you would run it the same way. dofile ("Pizza.lua") Maybe this isn't the real problem. If I could see the code you used to run it, and the code in the first few lines of your script, then I might be able to determine the problem.

  • HappyDog
    8th Jan 2021 Member 0 Permalink

    It's part of large script. Maybe i need delete "Grafito"?

     

     

     

    ---------------------------------GRAFITO---------------------------------------

     

    local graphite = elem.allocate("KEV", "Grph")

    elem.element(graphite, elem.element(elem.DEFAULT_PT_IRON))

    elem.property(graphite, "Name", "GRPH")

    elem.property(graphite, "Description", "Graphite. Absorbs neutrons and photons.")

    elem.property(graphite, "Color", 0x1E1B1B)

    elem.property(graphite, "Flammable", 5)

    elem.property(graphite, "Properties", elem.TYPE_PART)

    elem.property(graphite, "Weight", 20)

    elem.property(graphite, "Meltable",1)

     

    local function grafUpdate(i, x, y, s, nt)

        r = sim.partID(x+math.random(-1,1),y+math.random(-1,1))

        if r~= nil then

            if sim.partProperty(r, "type") == elem.DEFAULT_PT_OXYG then

                sim.partChangeType(r, elem.DEFAULT_PT_CO2)

                sim.partKill(i)

            end

            if sim.partProperty(r, "type") == elem.DEFAULT_PT_FIRE then

                sim.partProperty(r, "type", carbono)

                sim.partKill(i)

            end

            if sim.partProperty(r, "type") == elem.DEFAULT_PT_OXYG then

                sim.partProperty(r, "type", carbono)

                sim.partProperty(i, "type", elem.DEFAULT_PT_CO2)

            end

            if sim.partProperty(r, "type") == elem.DEFAULT_PT_PROT then

                sim.partProperty(r, "type", C14)

                sim.partProperty(i, "type", elem.DEFAULT_PT_NEUT)

            end

            if sim.partProperty(r, "type") == elem.DEFAULT_PT_NEUT then

                sim.partKill(r)

            end

            if sim.partProperty(r, "type") == elem.DEFAULT_PT_PHOT then

                sim.partKill(r)

            end

        end

    end

    elem.property(graphite, "Update", grafUpdate)

     

  • HappyDog
    11th Jan 2021 Member 0 Permalink
  • CactusHamster
    13th Jan 2021 Member 0 Permalink

    Wherever you use something like sim.partProperty(r, "type", carbono), instead of putting just the element's name, you need to have its identifier. This can be something like elem.KEV_PT_GRPH or something like tpt.element('grph').

     

    Also, a quick note, when using TPT's default elements, like elem.DEFAULT_PT_PHOT, it goes way faster using the element's number instead. For example, you could use 18 instead of elem.DEFAULT_PT_NEUT. This helps the element's lag. You can find any element's number by typing it in the format I already mentioned (elem.IDENTIFIER_PT_ELEMENT or tpt.elem('element') ) in the game's console.

  • jacob1
    13th Jan 2021 Developer 0 Permalink
    I don't actually get any error running this script. It works totally fine, and there is no '%' in the source code. The 'GRAFITO' comment is fine. How are you running it? I recommend via the script manager, but dofile() is also ok.

    @CactusHamster (View Post)
    You are correct with how to check element types with elem.KEV_PT_GRPH. But this script is already doing that properly, so nothing needs to be changed.

    Second, it is in fact not at all faster to use 18 instead of elem.DEFAULT_PT_PHOT. Please do not hardcode numbers into your Lua scripts, they will break in the future. Constants such as element identifiers do not need to make a TPT api call back to C code, so therefore are just as fast as pure Lua. Edit: but, tpt.element() calls are actually slower, so avoid this.
    Edited 2 times by jacob1. Last: 13th Jan 2021
  • HappyDog
    17th Jan 2021 Member 0 Permalink

    @jacob1 (View Post)

     

    I get script on this website: https://starcatcher.us/script

     

    107) CHEMMOD V1