Favorite elements menu

  • jacob1
    2nd Oct 2011 Developer 1 Permalink
    Edit 3/16/12: This has been discontinued for a very long lime, because I have a mod now. It includes every single feature this has, and has improved almost all of them, plus added tons of features this doesn't have. See the thread here for more info + a download. You can still use the useful functions from this in your lua script if you want with credit (-- By Jacob1) on the function name

    This is a Lua script that lets you put all of your favorite elements in one menu. It actually does a lot more than just a favorite elements menu, because when I think of a cool new thing to do, I try and add it. So far, I have also added a new HUD, a way to add certain Lua code to a save, and moving solids. This might sound fake, but it is real and the download link is at the bottom. In this post, I will explain how everything works.

    FAVORITES MENU:
    When you go to the tools menu, Any elements you used recently or clicked on will appear. Right click one to permanently save or unsave it to the menu. It will still be there even after you exit the powder toy. Left click any of them to start drawing with it. The scroll wheel can't be used, so use (Alt +) [ and ] to change the size. Pressing Ctrl+Shift activates a very glitchy floodfill. Also, if you click the more button, a different menu will appear. It has different options that you can click to do certain things, like the HUD or custom functions.

    HUD:
    To use the HUD, click the hud button in the second menu. Clicking it again will go into debug mode and clicking it a third time will also display particle indexes on the hud. You can press 'd' instead. The hud looks almost exactly like the original, but it's a little different. Instead of the version number it displays the time and date. The FPS and temperatures go out to more decimal places in debug mode, and Farenheit temperatures are also displayed. It does not show pressure or gravity, so if you want to see those, press Ctrl-H.

    MOVING SOLIDS:
    To use moving solids, just draw EQVE using the favorites menu. It draws a circle the same size as the radius. Smaller balls are bouncy and extremely big ones are glitchy. It is possible to have more than one ball out at once, but if one ball goes offscreen any balls that were drawn after that will fall apart. Also, If you make all the balls the same color then they will go through eachother.

    LUA CODE:
    Adding Lua functions to a save is one of the most usefull things in this script. Put code into luacode.txt and then click the add button. If there were any errors, it will tell you what line it was on. Diamond will then appear in the top left corner and the code will start running every frame. Anyone with this script that opens the save will use it too. Not all Lua code works, so you can only use certain things. If/then/else/elseif/end works, but for/while loops do not yet. Here is a list of functions you can use:

    tpt.drawrect(x,y,w,h,r,g,b,a,fill)

    tpt.drawcircle(x,y,rd,r,g,b,a,fill)

    tpt.drawtext(x,y,text,r,g,b,a)

    tpt.set or tpt.set_property(function overload number,other parameters...) This is the only one that you don't need to use every parameter for. Only enter the ones needed. To find the overload number, look at the wiki. The first is 1 and the last is 8. If you want to put in a element name, type this: ...,tonum("dmnd")) Also, input temperatures in Celcius, not Kelvin. You might need to use tpt.number(temp)

    tpt.create_line or tpt.create(x1,y1,x2,y2,radius,tonum(type))

    tpt.delete(x,y) or tpt.delete(index,a number larger than 384)

    tpt.get_property(property,x,y) or tpt.get_property(property,index,large number) Returns a value, so does nothing by itself

    tpt.num or tpt.number(number) Used to represent large,negetive,or decimal numbers. Do not use a decimal point in the number, use p or _ instead

    math.random(a,b) Produces a random int between a and b

    to use variables, type tpt.var(varnum) = x Instead of equals, you can also use +=, -=, /=, *=, %=, or ^=.

    To get a variable without changing it, type tpt.getvar(varnum) You can use this in if statements. Also, variable 1 is set to 1 by default before you start the code, and the rest are nil. You need to initialize them like this: if tpt.getvar(1) == 1 then ... tpt.var(1) = 0 end or else it will try to compare something with a nil variable in any if statements.

    There are special variables like mousex and keychar above 200. There are a lot, so look at the source near the bottom to figure out how to use them

    When you use if statements, you can use == ( or =, there is no difference), ~=/!=, >, >=, <, and <=.

    You can also use while loops, but they might not work if you have if statements/another while loop inside

    Also, functions that return something can be used as parameters in functions and you can use comments. Just make sure there is a space before and after the comment

    OTHER FEATURES:
    There are a few other features in this script I haven't explained. For example, if you edit the 3 custom functions in the script, you can make your own buttons that do things. Also, you can put a password on the powder toy to prevent others from using it. If you click the find button in the second menu, it will find the first element in your favorites menu and paint it red, making it easy to find out where a certain element is in a save. The paint button lets you paint without pressing b. The last thing I haven't explained yet is the info button. This script keeps track of your FPS and time played, and hitting this button will display those statistics.

    If you have questions or ideas please post them. I am working on making a save that shows what this can do and I will try and finish it by the end of this weekend. I will also update this script sometimes, but I don't have that much time to work on it because of school. Most of this was actually done in the first half of summer.

    This script works with any version of Powder Toy that has Lua, but not all features are available in the older ones. I have been working on it since the Lua console came out, so I didn't want to not make it work in old versions. In older versions, it appears in the smallest menu and might have extra options like floodfill that were replaced by keys later.

    Download


    Version 1.1: Fixed nested if loops and totalfps glitch
    Version 1.2: Added paint button, by gamax92. Use the number keys and backspace to choose a color. When you are drawing an element, the element you have selected in the normal Powder Toy won't be drawn too. Added ability to add while loops to save. Improved speed when using HUD bebug mode 2.
    Version 2.0: Almost no lag when drawing menu with newer versions. Better HUD with more decimal points, name of months and weekdays, and 12 hour clock. Also, press 'd' to switch in and out of debug mode. Fixed keys to switch hud and go into floodfill. You can save/load stamps while drawing or painting. Made it more obvious that you could change the values in the paint box, just put your mouse over one and start typing.
    Version 2.1: Added elements from version 65
    Version 2.2: You can click the arrow to hide/unhide the menu, fixed TESC drawing/really fixed LIGH drawing
    Version 2.3: Added ELEC/FIGH, changed gol drawing, made hud switch shortcut shift+h instead of ctrl+h, because that is used now. Fixed keys with num/caps lock on. There are 4 versions of this, because I fixed glitches I accidentally created 4 times.
  • alecnotalex
    2nd Oct 2011 Member 0 Permalink
    @jacob1 (View Post)
    Haven't got a chance to download and test it, but I'm very impressed. It sounds really good. You get my respect.
  • MasterMind555
    2nd Oct 2011 Member 0 Permalink
    @jacob1 (View Post)
    Did you write all that?
    All by yourself?
  • jacob1
    2nd Oct 2011 Developer 1 Permalink
    @MasterMind555 (View Post)
    I wrote it over a few months, it's not like I did it all at once. I just added something new whenever I felt like it. Right now, i am trying to add the ability to add while loops to a save and i fixed nested if loops.
  • MasterMind555
    2nd Oct 2011 Member 0 Permalink
    @jacob1 (View Post)
    Do you know a programming language ( Not a scripting language )? Because you've got talent and you should use it
  • jacob1
    2nd Oct 2011 Developer 1 Permalink
    @MasterMind555 (View Post)
    I took a programming class in school last year and learned java. I realized it was close to c/c++ and so I started using that to make/modify programms. Lua was easy to learn from what I already know, so I used it to make this. I don't know the most complicated stuff of any language but I am planning on going to college for computer science and learning more.
  • MasterMind555
    2nd Oct 2011 Member 0 Permalink
    @jacob1 (View Post)
    You should probably learn C a bit more in depth and start a mod, it would probably be alot better then a lua script.
  • alecnotalex
    2nd Oct 2011 Member 0 Permalink
    @jacob1 (View Post)
    You really should learn C as much as you can, you are incredibly talented.
  • jacob1
    2nd Oct 2011 Developer 1 Permalink
    I was going to learn c, but I never did. I probably still know enough to start a mod that has all of this in it. I actualIy did make a mod with a favorites menu, but it was very laggy, even if i compiled the source with no changes, so I never used it. Sometime later I will try and make it again and release it, even if it is slower.
  • MasterMind555
    2nd Oct 2011 Member 0 Permalink
    @jacob1 (View Post)
    It is maybe slower in the IDE, but it should be normal speed once exported.
Locked by jacob1: necro