Can't seem to understand particle flags

  • humanoidbob
    12th Jan 2012 Member 0 Permalink
    I don't understand what's wrong with this line of code in my new element:
                        int photf = pmap[posx-1][posy].flags;
    This was the message:
    C:\Program Files\SmartGit 2.1\bin\The-Powder-Toy\src\elements\solar.c82error: request for member 'flags' in something not a structure or union
    In the code line, posx and posy were int variables for the position of the current particle.
    Could someone please tell me what's wrong?
  • jacksonmj
    12th Jan 2012 Developer 0 Permalink
    pmap does not actually contain the particle data, it just tells you which particle is in each position. pmap is a 2D array of unsigned integers, and each element of it stores the type and index of the particle in that position (if any).
    If the pmap value is r, then r&0xFF is the type of the particle, and r>>8 is the index in the parts array.

    An example:
    unsigned r = pmap[posx-1][posy]; //Get the pmap value
    if (r&0xFF) //if there's a particle there
    {
    //Do stuff
    int photf = parts[r>>8].flags;
    }
  • humanoidbob
    12th Jan 2012 Member 0 Permalink
    Thanks! Also, do you think that there would be a way to automatically run a script at startup?
  • mniip
    12th Jan 2012 Developer 0 Permalink
    @humanoidbob (View Post)
    autorun.lua is ran on startup
  • jenn4
    12th Jan 2012 Member 0 Permalink
    @mniip (View Post)
    @humanoidbob (View Post)
    Mniip means that if you make a text file in TPTs archive, paste code in and change format to .lua it will be automatically run by TPT in startup.
  • limelier
    12th Jan 2012 Member 0 Permalink
    @jenn4 (View Post)
    No, he means the file actually has to be named "autorun.lua", not bleh.lua, that won't be ran on startup.
  • humanoidbob
    12th Jan 2012 Member 0 Permalink
    Thanks! I think that this will work!
    How do you exit the program from inside this file? I want to make a password so my brother can't get in.
  • limelier
    12th Jan 2012 Member 0 Permalink
    You can't, afaik.
  • jacob1
    12th Jan 2012 Developer 0 Permalink
    You can exit a program using os.exit(), and make the password like this:

    thepassword = "thepowdertoy"
    local pass = tpt.input("password", "Enter the password or \"quit\" to quit")
    while pass ~= thepassword do
        if pass == "quit" then os.exit() end
        pass = tpt.input("password", "Wrong password, try again or \"quit\" to quit")
    end

    It does give you unlimited tries, and the password isn't secret at all, but it still should work good with a good password