Error: = or in expected near . pls help

  • powder_is_epic
    9th May Member 0 Permalink

    This code keeps giving me the error, please help me figure out why. Specifically the for loop is causing the error.

    -- Update and Graphics functions.
    function GMPRup(i, x, y, s, nt)

    for r in sim.neighbors(x,y,1,1) do

    if (sim.partProperty(r, "type") == elem.DEFAULT_PT_SPRK) then
    -- Credit to Jerehmia for helping me figure out how sim.partProperty worked.
    sim.partProperty(i, sim.FIELD_TMP, sim.partProperty(i, sim.FIELD_TMP) + 1)

    end
    -- Sleep function from some random website on the internet.
    local clock = os.clock
    function sleep(n)
    local t0 = clock()
    while clock() - t0 <= n do end
    end

    for sim.partProperty(i, sim.FIELD_TMP), 1, 10, -1 do

    sleep(2)

    if s ~= nt then

    for dx = -1, 1 do
           
    for dy = -1, 1 do
           
    if dx ~= 0 or dy ~= 0 then
           
    sim.partCreate(-1, x + dx, y + dy, elem.DEFAULT_PT_SPRK)

    end

    end

    end
  • ArolaunTech
    9th May Member 0 Permalink

    What line is the error on?

  • powder_is_epic
    10th May Member 0 Permalink

    for sim.partProperty(isim.FIELD_TMP), 110-1 do

    that line

  • jacob1
    10th May Developer 0 Permalink
    For help with Lua, I'd recommend you find an online guide, like this one . Reading up to section 4 would get you familiar with control structures like for loops.

    There's also the Lua manual, I use this a lot.

    That for loop simply isn't valid Lua, and I don't know what you're trying to do, so I think you should use some of those guides to understand the language better.

    Also, you should remove that sleep function. Sleeping within element update functions would lag the game so hard, and you've just created an expensive busy loop that will waste CPU time.
  • powder_is_epic
    10th May Member 0 Permalink

    heres what i want to do. i want so when SPRK is beside QMPR it adds +1 to tmp then a few seconds later sparks all elements around it as many times as the number of tmp, as long as it is not higher then 10 or lower then 1, like a transistor/capacitator kinda thing. because quantum computing allows you to save signals that are at 0.4 or 0.6 instead of 0 and 1. also yeah this element is kinda laggy. anyways ima read that guide. EDIT okay my code is this now:

     

    fv = sim.partProperty(i, sim.FIELD_TMP, sim.partProperty(i, sim.FIELD_TMP) +0)

    for fv, 1, 10, -1 do
     
    but now im getting <name> expected near 1
    all im trying to do is what the guide says i need to do i have a variable im iterating by, a range (1 through 10) and -1 so each time it runs it subtracts one from the tmp value. so i have no idea why this aint working, and i tried:
     
    for fv=sim.partProperty(i, sim.FIELD_TMP, sim.partProperty(i, sim.FIELD_TMP) +0), 1, 10, -1 do
     
    and that doesnt work EITHER.
    this whole issue is probably that i did something you can only do in python or something stupid lol. and when i figure it out im gonna look like a idiot ngl.
    Edited 5 times by powder_is_epic. Last: 10th May
  • creator_of_fail
    10th May Member 0 Permalink

    To get around using sleep functions, you could use PROP_LIFE_DEC in element properties and that acts like a clock that drops by 1 every frame. Then you could set life to 100 for example and create a check for when life hits 0.

     

    Also, here's a sample for loop from one of my scripts:

    for range=1,sim.partProperty(i,sim.FIELD_TMP4) do
          shift(i,range,direction)
    end

  • powder_is_epic
    10th May Member 0 Permalink

    ANOTHER ERROR - so i found a function online that lets me do for loops like in Python, so i finally have that sorted out, but now im getting this error - NUMBER EXPECTED, GOT NIL - for this line of code.

     

    i = sim.partProperty(i, sim.FIELD_TMP, sim.partProperty(i, sim.FIELD_TMP) +0)
     
    kinda confused here cause i used this exact like of code earlier and im pretty sure it works
    Edited 2 times by powder_is_epic. Last: 11th May
  • creator_of_fail
    11th May Member 0 Permalink

    @powder_is_epic (View Post)

     This is in your update function right? I'm not too sure what you are trying to do with that but there's already an i in the update function which is the index of the particle and reusing variables can have confusing results.

  • powder_is_epic
    11th May Member 0 Permalink

    ooooh