Seite 5 von 7 ErsteErste 1 2 3 4 5 6 7 LetzteLetzte
Zeige Ergebnis 121 bis 150 von 188

Lua Scripts/Examples/Snippets

This is a discussion on Lua Scripts/Examples/Snippets within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Yes, especially in Lua (because it is a dynamically typed language) you can do this: Code: color = Color.new; pad ...

  
  1. #121
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Yes, especially in Lua (because it is a dynamically typed language) you can do this:
    Code:
    color = Color.new;
    pad = Controls.read;
    
    -- use
    red = color( 255, 0, 0 );
    curentPadState = pad();



  2. #122
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    this will let you check for a file

    Code:
    assert()
    so to make a file check function

    Code:
    function file_check(file_path)
    file = assert(io.open(file_path))
    if file == nil then
    screen:print(10, 10, "the file path was invalid")
    else
    screen:print(10, 10, "the file path was valid")
    end
    end
    by using assert there is no need to actually open the file or close it so it should be much quicker

    you can also return custom error messages using this command and create an error handler for your programs

    - i dont have an example error handler but this is sort of how assert is used

    Code:
    if condition then
    assert(test, "message")
    end
    this code means that if the condition is met then it will carry out the assert command so say if file == nil then you would use

    Code:
    if file == nil then
    assert(file == nil, "this file is invalid")
    end
    if there is no message then the command can be used to check values and will return either false or nil so if the error or condition is false it wont be executed, but if it is nill it will assert the command given

    - an example of this is the code used at the top of my post

    that is the part of the code that is seen as the test

    Code:
    io.open(file_path)
    in the top post no message was passed

    the error messages come out the same was as if an error is returned in lua player with a black screen and a white error message

    thanks
    ------ FaT3oYCG -----
    AKA Craig, call me what you want to It's your preference.
    My Website: http://www.modern-gamer.co.uk/

    Currently working on:
    (0) MediaGrab
    (0) PGE Gears Of War - On hold (Very large project).
    (0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).

  3. #123
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    oh here is a handy little charge bar function i made all you need to do is put this

    above while true do

    Code:
    function charge_bar_horizontal(xpos, ypos)
    
    green = Color.new(0, 255, 0)
    black = Color.new(0, 0, 0)
    white = Color.new(255, 255, 255)
    
    Charge = {}
    Charge.percentage = System.powerGetBatteryLifePercent()
    
    screen:fillRect(xpos, ypos, 138, 12, white)
    screen:fillRect(xpos + 1, ypos + 1, Charge.percentage, 10, green)
    screen:drawLine(xpos + 1, ypos + 1, xpos + 1, ypos + 10, black)
    screen:drawLine(xpos + 11, ypos + 1, xpos + 11, ypos + 10, black)
    screen:drawLine(xpos + 21, ypos + 1, xpos + 21, ypos + 10, black)
    screen:drawLine(xpos + 31, ypos + 1, xpos + 31, ypos + 10, black)
    screen:drawLine(xpos + 41, ypos + 1, xpos + 41, ypos + 10, black)
    screen:drawLine(xpos + 51, ypos + 1, xpos + 51, ypos + 10, black)
    screen:drawLine(xpos + 61, ypos + 1, xpos + 61, ypos + 10, black)
    screen:drawLine(xpos + 71, ypos + 1, xpos + 71, ypos + 10, black)
    screen:drawLine(xpos + 81, ypos + 1, xpos + 81, ypos + 10, black)
    screen:drawLine(xpos + 91, ypos + 1, xpos + 91, ypos + 10, black)
    screen:drawLine(xpos + 101, ypos + 1, xpos + 101, ypos + 10, black)
    
    screen:fillRect(xpos + 104, ypos + 1, 33, 10, black)
    
    screen:print(xpos + 106, ypos + 2, Charge.percentage .. "%", white)
    
    end
    and then to use it it only takes two arguments and x co-ordinate and a y co-ordinate like this

    Code:
    charge_bar_horizontal(10, 10)
    if you wanted to blit it to an empty image that has been created then you could use this

    Code:
    function charge_bar_horizontal(display, xpos, ypos)
    
    green = Color.new(0, 255, 0)
    black = Color.new(0, 0, 0)
    white = Color.new(255, 255, 255)
    
    Charge = {}
    Charge.percentage = System.powerGetBatteryLifePercent()
    
    display:fillRect(xpos, ypos, 138, 12, white)
    display:fillRect(xpos + 1, ypos + 1, Charge.percentage, 10, green)
    display:drawLine(xpos + 1, ypos + 1, xpos + 1, ypos + 10, black)
    display:drawLine(xpos + 11, ypos + 1, xpos + 11, ypos + 10, black)
    display:drawLine(xpos + 21, ypos + 1, xpos + 21, ypos + 10, black)
    display:drawLine(xpos + 31, ypos + 1, xpos + 31, ypos + 10, black)
    display:drawLine(xpos + 41, ypos + 1, xpos + 41, ypos + 10, black)
    display:drawLine(xpos + 51, ypos + 1, xpos + 51, ypos + 10, black)
    display:drawLine(xpos + 61, ypos + 1, xpos + 61, ypos + 10, black)
    display:drawLine(xpos + 71, ypos + 1, xpos + 71, ypos + 10, black)
    display:drawLine(xpos + 81, ypos + 1, xpos + 81, ypos + 10, black)
    display:drawLine(xpos + 91, ypos + 1, xpos + 91, ypos + 10, black)
    display:drawLine(xpos + 101, ypos + 1, xpos + 101, ypos + 10, black)
    
    display:fillRect(xpos + 104, ypos + 1, 33, 10, black)
    
    display:print(xpos + 106, ypos + 2, Charge.percentage .. "%", white)
    
    end
    then to use that

    Code:
    blank_image = Image.createEmpty(200, 200)
    blank_image:clear()
    
    screen:blit(10, 10, blank_image)
    
    charge_bar_horizontal(blank_image, 10, 10)
    EDIT:

    here is what it looks like


    thanks
    Geändert von FaT3oYCG (01-19-2008 um 02:07 PM Uhr)
    ------ FaT3oYCG -----
    AKA Craig, call me what you want to It's your preference.
    My Website: http://www.modern-gamer.co.uk/

    Currently working on:
    (0) MediaGrab
    (0) PGE Gears Of War - On hold (Very large project).
    (0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).

  4. #124
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    simpler less cpu-using charge function that only redraws the battery bar when the battery life goes down enough to change the size of the bar:
    Code:
    cb = {w = 100, h = 10,c = Color.new(255,0,0)}
    cb.i = Image.createEmpty(cb.w,cb.h)
    cb.lbpc = (cb.w+2)*(100/cb.w)
    function updateCB()
    	cb.bp = System.getBatteryLifePercent()
    	if math.abs(cb.lbpc-cb.bp)*100 >= cb.w then
    		cb.lbpc = cb.bp
    		cb.i:clear()
    		cb.i:fillRect(0,0,cb.w*cb.bp/100,cb.h,cb.c)
    	end
    end
    Geändert von TurtlesPwn (01-17-2008 um 04:06 PM Uhr)

  5. #125
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    here is the code for a menu that is as simple as i can get it at the moment

    -- to add more items variables need to be changed and to accept input more code must be added but if you run this code you will see what it does and why it is simple

    Code:
    white = Color.new(255,255,255)
    red = Color.new(255,0,0)
    
    option = { "spot - 1 -", "spot - - 2 - -", "spot - - - 3 - - -" }
    
    current = 1
    
    oldpad = Controls.read()
    
    while true do
    
    pad = Controls.read()
    
    screen:clear()
    
    for i = 1, 3 do
    screen:print(10, 10 * i, option[i], white)
    screen:print(10, 10 * current, option[current], red)
    end
    
    if pad:up() and oldpad:up() ~= pad:up() and current > 1 then
    current = current - 1
    end
    if pad:down() and oldpad:down() ~= pad:down() and current < 3 then
    current = current + 1
    end
    
    screen.flip()
    screen.waitVblankStart()
    
    oldpad = pad
    
    end
    and here is a very advanced menu code that uses functions for the variable values to save time for the coder

    Code:
    white = Color.new(255,255,255)
    red = Color.new(255,0,0)
    
    option = { "spot - 1 -", "spot - - 2 - -", "spot - - - 3 - - -" }
    
    current = 1
    
    function menu_setup(table_name, start_index, end_index)
    for i = start_index, end_index do
    screen:print(10, 10 * i, table_name[i], white)
    screen:print(10, 10 * current, table_name[current], red)
    end
    end
    
    function menu_controls(min_index, max_index)
    if pad:up() and oldpad:up() ~= pad:up() and current > min_index then
    current = current - 1
    end
    if pad:down() and oldpad:down() ~= pad:down() and current < max_index then
    current = current + 1
    end
    end
    
    oldpad = Controls.read()
    
    while true do
    
    pad = Controls.read()
    
    screen:clear()
    
    menu_setup(option, 1, 3)
    menu_controls(1, 3)
    
    screen.flip()
    screen.waitVblankStart()
    
    oldpad = pad
    
    end
    use that if you want it straight in your code and a layout like this if you want it in a separate file - you need to use pad and oldpad or change the menu.lua file corresponding to what you have used instead of pad and oldpad

    menu.lua
    Code:
    function menu_setup(table_name, start_index, end_index)
    for i = start_index, end_index do
    screen:print(10, 10 * i, table_name[i], white)
    screen:print(10, 10 * current, table_name[current], red)
    end
    end
    
    function menu_controls(min_index, max_index)
    if pad:up() and oldpad:up() ~= pad:up() and current > min_index then
    current = current - 1
    end
    if pad:down() and oldpad:down() ~= pad:down() and current < max_index then
    current = current + 1
    end
    end
    index.lua
    Code:
    white = Color.new(255,255,255)
    red = Color.new(255,0,0)
    
    option = { "spot - 1 -", "spot - - 2 - -", "spot - - - 3 - - -" }
    
    current = 1
    
    oldpad = Controls.read()
    
    while true do
    
    pad = Controls.read()
    
    screen:clear()
    
    menu_setup(option, 1, 3)
    menu_controls(1, 3)
    
    screen.flip()
    screen.waitVblankStart()
    
    oldpad = pad
    
    end
    ok here is the code in a file that will just run it will display the amount of items chosen by the user maximum and move the menu up one every time down is pressed and up one every time up is pressed if you wanted the menu to come from the bottom of the screen then you would just reverse the the y code

    Code:
    white = Color.new(255,255,255)
    red = Color.new(255,0,0)
    
    option = { "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15", "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31", "s32", "s33", "s34", "s35" }
    
    current = 1
    
    function menu_setup(table_name, max_index)
    for i = current, max_index do
    screen:print(10,10 + 10 * i - current * 10, table_name[i], white)
    screen:print(10,10 + 10 * current - current * 10, table_name[current], red)
    end
    end
    
    function menu_controls(min_index, max_index)
    if pad:up() and oldpad:up() ~= pad:up() and current > min_index then
    current = current - 1
    end
    if pad:down() and oldpad:down() ~= pad:down() and current < max_index then
    current = current + 1
    end
    end
    
    oldpad = Controls.read()
    
    while true do
    
    pad = Controls.read()
    
    screen:clear()
    
    screen:print(10, 0, current, red)
    
    menu_setup(option, 30)
    menu_controls(1, 30)
    
    screen.flip()
    screen.waitVblankStart()
    
    oldpad = pad
    
    end
    this could easily be modified to be a file browser by putting the_end = table.getn(System.listDir ectory()) and then changing this line

    Code:
    menu_setup(option, 30)
    to

    Code:
    menu_setup(table.getn(System.listDirectory()), the_end)
    and setting the rest up as a file browser so that the other controls e.g. cross go to the next directory you would do this by putting current.name

    like this

    Code:
    if pad:cross() and oldpad:cross() ~= pad:cross() then
    System.currentDirectory(option[current])
    current = 1
    the_end = table.getn(System.listDirectory())
    end
    thanks

    [email protected]

    p.s. i will post a more advanced menu than this soon when i modify it to automatically change the menu's position depending on the current menu item

    p.p.s. turtlespwn wouldn't your code constantly check if the new value is smaller or bigger than the old one therefore using the same amount of cpu maybe even more than mine, if not could you please explain why
    Geändert von FaT3oYCG (01-26-2008 um 01:44 AM Uhr)
    ------ FaT3oYCG -----
    AKA Craig, call me what you want to It's your preference.
    My Website: http://www.modern-gamer.co.uk/

    Currently working on:
    (0) MediaGrab
    (0) PGE Gears Of War - On hold (Very large project).
    (0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).

  6. #126
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    each loop to draw the bar, yours does this:
    -declare three colors
    -create a table, put System.getBatteryLifePerc ent() into it
    -3 screen:fillRect()s
    -11 screen:drawLine()s
    -a screen print
    -lots of math among all of that

    each loop, mine does this:
    -1 screen:blit()
    -update the battery percentage value
    -check if the battery charge percentage has changed enough to affect the size of the bar
    ------if so redraw the battery bar

    And, all but the first part of mine needn't even be done every loop. If you want, you could run them every 3600 loops - once per minute (about the time it takes to charge 1% during the fast charge stage (pre-80% charge))

    Trust me, if you want, I'll make a speed comparison test and the results will show that mine is SIGNIFICANTLY faster than yours.

    Also, if you want a true SUPER SIMPLE menu, make each option able to be given a function to execute when X is pressed with it chosen, and turn the entire thing into about 15 lines. Yes, it is possible.

    edit: also, your filebrowser modification guide will not work. System.listDirectory returns in a much different way than you seem to be using it. You set current to a number and then use current.name as a string when current is a table index. You also attempt to use System.currentDirectory without checking that the selected item is actually a directory.

  7. #127
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von TurtlesPwn
    each loop to draw the bar, yours does this:
    -declare three colors
    -create a table, put System.getBatteryLifePerc ent() into it
    -3 screen:fillRect()s
    -11 screen:drawLine()s
    -a screen print
    -lots of math among all of that

    each loop, mine does this:
    -1 screen:blit()
    -update the battery percentage value
    -check if the battery charge percentage has changed enough to affect the size of the bar
    ------if so redraw the battery bar

    And, all but the first part of mine needn't even be done every loop. If you want, you could run them every 3600 loops - once per minute (about the time it takes to charge 1% during the fast charge stage (pre-80% charge))

    Trust me, if you want, I'll make a speed comparison test and the results will show that mine is SIGNIFICANTLY faster than yours.

    Also, if you want a true SUPER SIMPLE menu, make each option able to be given a function to execute when X is pressed with it chosen, and turn the entire thing into about 15 lines. Yes, it is possible.

    edit: also, your file browser modification guide will not work. System.listDirectory returns in a much different way than you seem to be using it. You set current to a number and then use current.name as a string when current is a table index. You also attempt to use System.currentDirectory without checking that the selected item is actually a directory.
    - i wasn't having a go at you i just wanted to know why yours was faster
    - where did i use System.listDirectory() ?
    - current is the number, current is the numbers name in the table - the table is the memory stick directory - sorry my bad i have fixed it now i was wrong
    - i dont need to check if it is a directory - i have made a file browser but i didn't check if it was a dir or not and it worked fine i think that it is if it is a file it has an extension so doesn't open it if it doesn't have an extension then it opens it as a new directory

    - i didn't complete the code to make it a file browser it was just a suggestion

    - also i could have made a simpler charge bar but i was going for aesthetics not speed - which doesn't really matter in lua player any way



    EDIT:

    a while ago now i took a look at sg57's lua state snippet but since then i have improved it and added some more functions in that are very useful here it is

    Code:
    white = Color.new(255, 255, 255)
    black = Color.new(0, 0, 0)
    red = Color.new(255, 0, 0)
    green = Color.new(0, 255, 0)
    blue = Color.new(0, 0, 255)
    orange = Color.new(235, 115, 0)
    yellow = Color.new(255, 255, 0)
    
    state = { loading = 1, menu = 2, game = 3 }
    
    current_state = state.loading
    
    function Set_State(state_to_change_to)
    current_state = state_to_change_to
    end
    
    function Get_State()
    return current_state
    end
    
    function Start_States()
    if Get_State() == state.loading then
    -- do loading stuff
    screen:print(10, 10, "loading state", white)
    if pad:cross() and oldpad:cross() ~= pad:cross() then
    Set_State(state.menu)
    end
    elseif Get_State() == state.menu then
    -- do menu stuff
    screen:print(10, 10, "menu state", white)
    if pad:cross() and oldpad:cross() ~= pad:cross() then
    Set_State(state.game)
    end
    elseif Get_State() == state.game then
    -- do game stuff
    screen:print(10, 10, "game state", white)
    if pad:cross() and oldpad:cross() ~= pad:cross() then
    Set_State(state.loading)
    end
    end
    end
    
    oldpad = Controls.read()
    
    while true do
    
    pad = Controls.read()
    
    screen:clear()
    
    -- main
    
    Start_States()
    
    -- main
    
    if Controls.read():start() then
    break
    end
    
    screen.flip()
    screen.waitVblankStart()
    
    oldpad = pad
    
    end
    Geändert von FaT3oYCG (01-25-2008 um 05:49 PM Uhr)
    ------ FaT3oYCG -----
    AKA Craig, call me what you want to It's your preference.
    My Website: http://www.modern-gamer.co.uk/

    Currently working on:
    (0) MediaGrab
    (0) PGE Gears Of War - On hold (Very large project).
    (0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).

  8. #128
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    "- where did i use System.listDirectory() ?"
    When you set values based on table.getn(System.current Directory()), you should have been using it. currentDirectory returns a string of the current working directory that you're navigated to, not a table of the files in the current directory.
    "- i dont need to check if it is a directory - i have made a file browser but i didn't check if it was a dir or not and it worked fine i think that it is if it is a file it has an extension so doesn't open it if it doesn't have an extension then it opens it as a new directory"
    I don't think you've run it before - half your code for this one is broken. If you tried to cd to a file, I'm fairly certain it would get an error because it cannot find the folder. Lua isn't smart enough to check if something has an extension, and folder names can be named as if they have an extension anyways just as files can be named as if they don't.
    "- i didn't complete the code to make it a file browser it was just a suggestion"
    I know, but if you're going to walk people through how to do it, at least make sure your code will work - it is IMPOSSIBLE to make a filebrowser without System.listDirectory and you have it NOWHERE in your code.
    "- also i could have made a simpler charge bar but i was going for aesthetics not speed - which doesn't really matter in lua player any way"
    Speed doesn't matter in lua? Speed (or, code efficiency) is the most important thing in lua - lua being a fourth level language and using the slow graphics.h libraries and other restraints slowing it down, you MUST code as efficiently as possible, and you cannot let background things like a battery bar be slowing down your program. Besides, I could make my chargebar have the same aesthetics as yours while still being just as efficient as my current one.

  9. #129
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    ok ill change it to System.listDirectory() - i just looked at my code again i must have read it wrong

    - i dont know why the direcory thing works but i get no error

    here is the dir code - which is much the same as tacticalpenguins as i used his code to understand how file browsers work

    Code:
    if
    pad:cross() and oldpad:cross() ~= pad:cross()
    then
    System.currentDirectory(listitem[current].name)
    current = 1
    listitem = System.listDirectory()
    number = table.getn(listitem)
    end
    - and here is the file code


    Code:
    if
    pad:cross() and listitem[current].directory == false
    then
    if
    string.sub(listitem[current].name, -4) == ".lua"
    then
    screen:clear()
    dofile(listitem[current].name)
    end
    end
    and that works fine no errors

    - i did not know that lua player was that inefficient but i will think about the way i code now thanks

    - i dont like starting arguments and i wasn't trying too but on the Internet the way you word a reply decides the mood or tone that the reader thinks it was in when i reply to messages it tends too look like i am having a go at people but im not trying to sorry

    thanks

    [email protected]

    p.s. woooooooooo this was my 777'th post lol

    here is a simple script that will help you to understand how draw line works it also helps for when you are trying to see from perspective

    screenie:



    Code:
    white = Color.new(255, 255, 255)
    
    x = 20
    y = 20
    x1 = 10
    y1 = 10
    gap = 20
    block = Image.createEmpty(gap * 2, gap * 2)
    block:clear(white)
    
    oldpad = Controls.read()
    
    while true do
    
    pad = Controls.read()
    
    screen:clear()
    
    -- insert your main code here
    
    screen:print(10, 10, x .. " " .. y, white)
    
    screen:blit(x - gap, y - gap, block)
    
    screen:drawLine(0, 0, x - gap, y - gap, white)
    screen:drawLine(480, 0, x + gap, y - gap, white)
    screen:drawLine(0, 272, x - gap, y + gap, white)
    screen:drawLine(480, 272, x + gap, y + gap, white)
    
    if pad:left() then
    x = x - 5
    end
    if pad:right() then
    x = x + 5
    end
    if pad:up() then
    y = y - 5
    end
    if pad:down() then
    y = y + 5
    end
    if pad:square() then
    x1 = x1 - 5
    end
    if pad:circle() then
    x1 = x1 + 5
    end
    if pad:triangle() then
    y1 = y1 - 5
    end
    if pad:cross() then
    y1 = y1 + 5
    end
    
    if pad:l() then
    screen:save("C:\\sc.png")
    end
    
    -- insert your main code here
    
    if Controls.read():start() then
    	break
    end
    
    oldpad = pad
    
    screen.flip()
    screen.waitVblankStart()
    
    end
    Geändert von FaT3oYCG (01-26-2008 um 06:23 AM Uhr)
    ------ FaT3oYCG -----
    AKA Craig, call me what you want to It's your preference.
    My Website: http://www.modern-gamer.co.uk/

    Currently working on:
    (0) MediaGrab
    (0) PGE Gears Of War - On hold (Very large project).
    (0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).

  10. #130
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von FaT3oYCG
    ok ill change it to System.listDirectory() - i just looked at my code again i must have read it wrong

    - i dont know why the direcory thing works but i get no error

    here is the dir code - which is much the same as tacticalpenguins as i used his code to understand how file browsers work

    Code:
    if
    pad:cross() and oldpad:cross() ~= pad:cross()
    then
    System.currentDirectory(listitem[current].name)
    current = 1
    listitem = System.listDirectory()
    number = table.getn(listitem)
    end
    - and here is the file code


    Code:
    if
    pad:cross() and listitem[current].directory == false
    then
    if
    string.sub(listitem[current].name, -4) == ".lua"
    then
    screen:clear()
    dofile(listitem[current].name)
    end
    end
    and that works fine no errors
    It's really bad when you can't even make stolen code work. If you're going to try to only take bits and pieces (of which there are like, 3 in a filebrowser) then at least learn to make it still work when you're done butchering it. What you've done is just as bad as stealing the whole thing and passing it off as your own. How could you have read it wrong while saying it works fine? Your code that you repeatedly insist works fine will not work.
    Zitat Zitat von FaT3oYCG
    - i did not know that lua player was that inefficient but i will think about the way i code now thanks
    Luaplayer itself isn't inefficient, it's people who code like you do and use up all the cpu power in the world for the smallest little things that make it appear that way. You just have to make your code actually do as little as possible to do what you want. You obviously have never made a decent project that needs all the CPU it can get - a battery bar like yours would kill everything.

    Also, your drawLine example could be cleaned up and simplified a lot:
    Code:
    white = Color.new(255, 255, 255)
    x = 0
    y = 0
    bs = 10
    b = Image.createEmpty(bs,bs)
    
    while true do
    	pad = Controls.read()
    	screen:clear(white)
    	screen:blit(x,y,b)
    
    	screen:drawLine(0,0,x,y)
    	screen:drawLine(479,0,x+bs,y)
    	screen:drawLine(0,271,x,y+bs)
    	screen:drawLine(479,271,x+bs,y+bs)
    
    	ax = pad:analogX()
    	ay = pad:analogY()
    	if math.abs(ax) > 24 then
    		x = x + ax/32
    	end
    	if math.abs(ay) > 24 then
    		y = y + ay/32
    	end
    
    	if pad:start() then break end
    	screen.flip()
    	screen.waitVblankStart()
    end

  11. #131
    lol
    Points: 20.859, Level: 91
    Level completed: 2%, Points required for next Level: 491
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    Whittier, CA
    Beiträge
    5.791
    Points
    20.859
    Level
    91
    Downloads
    0
    Uploads
    0

    Standard

    TurtlesPwn sure does Pwn alot.

  12. #132
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    file operations

    i hadnt really looked into file operations much before but after looking at how Nielkie used binary file io i have come up with some custom commands that you might find useful

    - i will post them on the snippets thread too so they can bee looked at and found easily

    ok there are two files or sections that you need

    if you use separate files, which i like to do to keep the main file clean, but i usually just have a functions.lua file or something alike, then this would be your file operations.lua or whatever you want to call it

    Code:
    function file_io_reset(operand)
    if operand == nil then
    end
    if operand == 1 then
    source_file = ""
    elseif operand == 2 then
    output_file = ""
    elseif operand == 3 then
    source_file = ""
    output_file = ""
    elseif operand == 4 then
    file_io_data_store = ""
    end
    end
    
    function file_io(source_io_file, output_io_file, mode)
    if mode == nil then
    end
    if mode == "cut" then
    source_file = io.open(source_io_file, "rb")
    file_io_data_store = source_file:read("*a")
    source_file:close()
    System.removeFile(source_io_file)
    file_io_reset(1)
    elseif mode == "paste" then
    output_file = io.open(output_io_file, "wb")
    output_file:write(file_io_data_store)
    output_file:close()
    file_io_reset(4)
    file_io_reset(2)
    elseif mode == "copy" then
    source_file = io.open(source_io_file, "rb")
    file_io_data_store = source_file:read("*a")
    source_file:close()
    output_file = io.open(output_io_file, "wb")
    output_file:write(file_io_data_store)
    output_file:close()
    file_io_reset(4)
    file_io_reset(3)
    end
    end
    that basically just holds all of the commands for the file io that i have made

    - if you just keep it in your main file then put it above while true do

    ok now this would be your main file if you referenced to the file io commands file

    Code:
    white = Color.new(255, 255, 255)
    
    dofile("./file_operations.lua")
    
    oldpad = Controls.read()
    
    while true do
    
    pad = Controls.read()
    
    screen:clear()
    
    -- insert your main code here
    
    if pad:cross() and not oldpad:cross() then
    file_io("./a.png", nil, "cut")
    end
    
    if pad:circle() and not oldpad:circle() then
    file_io(nil, "./b.png", "paste")
    end
    
    if pad:square() and not oldpad:square() then
    file_io("./b.png", "./a.png", "copy")
    file_io("./b.png", nil, "cut")
    end
    
    -- insert your main code here
    
    if Controls.read():start() then
    	break
    end
    
    oldpad = pad
    
    screen.flip()
    screen.waitVblankStart()
    
    end
    that is a quick example that works with any type of file i just used an image named a.png to test it

    i have only made copy, cut, and paste commands but that is all you need as moving a file would just be cut and paste at the same time, if you want to delete a file, just cut it, if you then cut another file that files data will take its place

    it can only obviously cut and paste certain sized files as there is limited memory in lua player

    - these functions could be optimized if you feel like it you could optimize them yourself and post it or just keep it to yourself, i just thought i would post these here for reference
    ------ FaT3oYCG -----
    AKA Craig, call me what you want to It's your preference.
    My Website: http://www.modern-gamer.co.uk/

    Currently working on:
    (0) MediaGrab
    (0) PGE Gears Of War - On hold (Very large project).
    (0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).

  13. #133
    Points: 2.984, Level: 33
    Level completed: 56%, Points required for next Level: 66
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    46
    Points
    2.984
    Level
    33
    Downloads
    0
    Uploads
    0

    Standard

    Code:
    white = Color.new(255,255,255)
    counter = Timer.new()
    counter:start()
    while true do
    screen:clear()
    currentTime = counter:time()
    screen:print(10,10,"Counter Time: " .. currentTime,white)
    if currentTime < 1000 then
    screen:print(100,100,"Less than 1000",white)
    end
    if currentTime > 1000 and currentTime < 2000 then
    screen:print(100,100,"Greater than 1000",white)
    end
    if currentTime > 2000 then
    counter:reset(0)
    counter:start()
    end
    screen.waitVblankStart()
    screen.flip() end
    Creates a little counter and says if the number is above or below 1000.

  14. #134
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Here's a visualizer I found on my PSP I wrote a long time ago. It can create the Window's screensaver Lines among many other neat visualizations.

    It's very readable, efficient and easily configurable. Mess with the constants for some pretty neat effects :o
    Code:
    -- General Constants
    Screen = { leftBound = 0,    topBound = 0,
               rightBound = 480, bottomBound = 272 }
    
    BACKGROUND_COLOR = Color.new(0,0,0) -- black bg
    
    -- Line specific constants
    NUM_LINES = 5
    NUM_LINES_PER_LINE = 5
    
    COLORS = {} -- manage respectively to match NUM_LINES
    COLORS[1] = Color.new(255,255,255)
    COLORS[2] = Color.new(255,0,0)
    COLORS[3] = Color.new(0,255,0)
    COLORS[4] = Color.new(0,0,255)
    COLORS[5] = Color.new(0,255,255)
    
    SPEEDS = {} -- manage respectively to match NUM_LINES
    SPEEDS[1] = 2
    SPEEDS[2] = 4
    SPEEDS[3] = 6
    SPEEDS[4] = 3
    SPEEDS[5] = 5
    
    -- General declarations and initiation(s)
    bPaused = false
    
    -- Line specific declarations and initiation(s)
    Line = {}
    for i = 1, NUM_LINES do
      Line[i] = { x = {}, y = {}, xspeed = {}, yspeed = {}, color = COLORS[i] }
      
      for j = 1, NUM_LINES_PER_LINE do
        Line[i].x[j] = math.random(Screen.leftBound,Screen.rightBound)
        Line[i].y[j] = math.random(Screen.topBound,Screen.bottomBound)
        Line[i].xspeed[j] = SPEEDS[i]
        Line[i].yspeed[j] = SPEEDS[i]
      end
    end
    
    -- All input-specific code should go in here
    function Input()
      bPaused = Controls.read():cross() -- hold X to freeze the visualizer
    end
    
    -- All thinking-specific code should go in here
    function UpdateLine(i)
      for j = 1, NUM_LINES_PER_LINE do
        if (Line[i].x[j] >= Screen.rightBound) then
          Line[i].xspeed[j] = -SPEEDS[i]
        elseif (Line[i].x[j] <= Screen.leftBound) then
          Line[i].xspeed[j] = SPEEDS[i]
        end
        
        if (Line[i].y[j] >= Screen.bottomBound) then
          Line[i].yspeed[j] = -SPEEDS[i]
        elseif (Line[i].y[j] <= Screen.topBound) then
          Line[i].yspeed[j] = SPEEDS[i]
        end
    
        if not bPaused then
          Line[i].x[j] = Line[i].x[j] + Line[i].xspeed[j]
          Line[i].y[j] = Line[i].y[j] + Line[i].yspeed[j]
        end
      end
    end
    
    -- All drawing-specific code should go in here (only exception is clearing the screen each loop)
    function DrawLine(i)
      for j = 1, NUM_LINES_PER_LINE do
        if j == NUM_LINES_PER_LINE then
          screen:drawLine (Line[i].x[j],   Line[i].y[j],
                           Line[i].x[1],   Line[i].y[1],
                           Line[i].color)
        else
          screen:drawLine (Line[i].x[j],   Line[i].y[j],
                           Line[i].x[j+1], Line[i].y[j+1],
                           Line[i].color)
        end
      end
    end
    
    while true do
      screen:clear(BACKGROUND_COLOR)
      
      Input()         -- input
    
      for i = 1, NUM_LINES do
        UpdateLine(i) -- think
        DrawLine(i)   -- draw
      end
    
      screen.waitVblankStart()
      screen.flip()
    end
    Thought someone may find it useful.

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  15. #135
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Oh, here's another thing i found embedded in a maze of folders in my COMMON folder :)

    It doesn't really have a name (?) but it's basically particles affected by gravity with varying speeds (darker the color, slower it goes). Makes some pretty neat visualizations when the particles form a line and it waves around and wiggles.

    (if your a fan of bleach - think of it like Byakuya's senbonsakura (spelling) where you can control where they go (looks like it))

    The last date modified says August 2006 and, IMO, isn't structured and designed as well as it could be. It gets the job done however and is relatively easy to configure and have fun with ;) If you can see a use for it (visualizer in an mp3 player, make it a weapon (be neat :P), etc.) go for it.
    Code:
    width = 480
    height = 272
    maxCells=500
    
    cells = {}
    
    for i = 1, maxCells do
      cells[i] = {nr = 0, x = 0.0, y = 0.0,
             diago = 551.7100687,
             xpos = 0, ypos = 0,
             lastXpos = 0, lastYpos = 0,
             speed = 0.0, xmov = 0.0, ymov = 0.0,
             cr = 0, cg = 0, cb = 0}
    end
    
    started=false
    mouseX = 240
    mouseY = 272
    
    function initCell(x,y,i)
        cells[i].nr=i
        cells[i].x=x
        cells[i].y=y
        cells[i].xpos=x
        cells[i].ypos=y
        cells[i].lastXpos=cells[i].xpos
        cells[i].lastYpos=cells[i].ypos
        while (cells[i].xmov==0 and cells[i].ymov==0) do
          cells[i].xmov=math.random(-1.0,1.0)
          cells[i].ymov=math.random(-1.0,1.0)
        end
        cells[i].speed=0.6+(i/(maxCells+0.0))*0.8
        cells[i].cr=255
        cells[i].cg=255*(cells[i].speed-0.6)/0.8
        cells[i].cb=128+127*(cells[i].speed-0.6)/0.8
    end
    
    function initialize()
      xs = 0.0
      ys = 0.0
      rx = 0.0
      ry = 0.0
      for i=1, maxCells do
        rx=width/4+math.random(-width/8,width/8)
        ry=height/4+math.random(-height/8,height/8)
        xs=width/2+rx*math.cos(6.28318*i/maxCells) -- 6.28318 is 2pi
        ys=height/2+ry*math.sin(6.28318*i/maxCells)
        initCell(xs,ys,i)
      end
    end
    
    function setup()
      initialize()
      started=true
    end
    
    function dist(x,y,x2,y2)
      return math.sqrt( math.pow((x2 - x), 2) + math.pow((y2 - y), 2) )
    end
    
    function update(i)
        d = dist(cells[i].x,cells[i].y,mouseX,mouseY)
        attrac=0.0010*(cells[i].diago-d)/cells[i].diago
    
        turn=false
    
        for i=1, 5 do
          iran=1+math.random(0,maxCells-1)
          md=math.random(1,4)
          if (dist(cells[iran].x,cells[iran].y,cells[i].x,cells[i].y)<md) then
            turn=true
            i=5
          end
        end
        if (turn) then
          cells[i].xmov=cells[i].xmov+math.random(-0.8,0.8)
          cells[i].ymov=cells[i].ymov+math.random(-0.8,0.8)
        end
    
        if (cells[i].x>width or cells[i].x<1) then
          cells[i].xmov=cells[i].xmov*-1
        end
        if (cells[i].y>height or cells[i].y<1) then
          cells[i].ymov=cells[i].ymov*-1
        end
    
        cells[i].xmov=cells[i].xmov+(mouseX-cells[i].x)*attrac
        cells[i].ymov=cells[i].ymov+(mouseY-cells[i].y)*attrac
        cells[i].xmov=cells[i].xmov+math.random(-0.02,0.02)
        cells[i].ymov=cells[i].ymov+math.random(-0.02,0.02)
    
        for j=1, 5 do
          if (cells[i].nr>j) then
            cells[i].xmov=cells[i].xmov+0.001*cells[cells[i].nr-j].xmov
            cells[i].ymov=cells[i].ymov+0.001*cells[cells[i].nr-j].ymov
          end
        end
    
        cells[i].xmov=cells[i].xmov*0.992
        cells[i].ymov=cells[i].ymov*0.992
        cells[i].x=cells[i].x+cells[i].xmov*cells[i].speed
        cells[i].y=cells[i].y+cells[i].ymov*cells[i].speed
        cells[i].xpos=cells[i].x
        cells[i].ypos=cells[i].y
    
        screen:drawLine(cells[i].xpos,cells[i].ypos,cells[i].lastXpos,cells[i].lastYpos, Color.new(cells[i].cr,cells[i].cg,cells[i].cb))
        cells[i].lastXpos=cells[i].xpos
        cells[i].lastYpos=cells[i].ypos
    end
    
    function draw()
      screen:clear(Color.new(0,0,0))
    
      if (started) then
        for i=1, maxCells do
          update(i)
        end
      end
      
      screen:drawLine(mouseX,mouseY,mouseX+5,mouseY+5,Color.new(0,255,0))
      screen:drawLine(mouseX,mouseY+5,mouseX+5,mouseY,Color.new(0,255,0))
    end
    
    function input()
      if Controls.read():cross() then
        setup()
      end
      
      if Controls.read():left() then mouseX = mouseX - 2 end
      if Controls.read():right() then mouseX = mouseX + 2 end
      if Controls.read():up() then mouseY = mouseY - 2 end
      if Controls.read():down() then mouseY = mouseY + 2 end
      
      if mouseY >= height then mouseY = height end
      if mouseY <= 0 then mouseY = 0 end
      if mouseX <= 0 then mouseX = 0 end
      if mouseX >= width then mouseX = width end
    end
    
    setup()
    
    while true do
      input()
      draw()
    
      screen.waitVblankStart()
      screen.flip()
    end
    One really sweet visual is to gather up speed by holding the X button. Let it loose and watch as this really cool 3dimensional figure slowly forms and rotates and slowly gets smaller and disappears :)
    Geändert von SG57 (02-29-2008 um 09:13 PM Uhr)

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  16. #136
    QJ Gamer Blue
    Points: 7.014, Level: 55
    Level completed: 32%, Points required for next Level: 136
    Overall activity: 0%

    Registriert seit
    Jan 2007
    Ort
    U.S.
    Beiträge
    405
    Points
    7.014
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    This reduces a fraction to it's simplest form. If the denominator is 1, it returns the numerator (i.e., if the fraction is 2/1, it returns 2), and if the denominator is 0 it returns undefined. It is based off of Euclid's algorithm, and thanks go to LMelior over at evilmana.com for pointing me to the following page, which describes the algorithm.
    http://en.wikipedia.org/wiki/Euclidean_algorithm

    Code:
    function simplify(num,denom)
             num2 = num
             denom2 = denom
    
             while (denom ~= 0) do
                   t = denom
                   denom = math.fmod(num,denom)
                   num = t
             end
             
             gcf = num
             
             if (denom2/gcf) ~= 1 and (denom2/gcf ~= 0) then
                simplified = (num2/gcf .. "/" .. denom2/gcf)
             elseif (denom2/gcf) == 1 then
                simplified = (num2/gcf)
             elseif (denom2/gcf) == 0 then
                simplified = "undefined"
             end
    end

  17. #137
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    hi another snippet here, i decided to make a scrolling marquee function for lua player, i messed around trying to make a function that would work well in many different ways but found that the best way was to print the string onto images and scroll the images from one side to the other, the function has options for the string to be used, the y position, the background colour, the text colour and the speed at which the string will cycle from one side of the screen to the other

    the direction of the marquee is determined by the speed if it is positive then the marquee will scroll from left to right if it is negative it will scroll from right to left, before circulating again

    - i found that a nice quick speed where the text is still readable is 1.2 and -1.2, and a good slow scrolling speed is 0.5 and -0.5, but that is just my opinion

    - i wouldn't choose speeds such as 20 as the letters and words will become unreadable

    - this code may be unefficient but it works perfectly with a small amount of calculations

    ok here is the code - this code will run if put into an lua file and played with either windows or psp lua player versions, without any modification

    Code:
    white = Color.new(255, 255, 255)
    black = Color.new(0, 0, 0)
    
    xpos = 0
    
    function scrolling_marquee(marquee_string, y_position, background_colour, text_colour, speed)
    
    xpos = xpos + speed
    
    string_len = (string.len(marquee_string) * 8)
    
    images_needed = math.ceil(string_len / 64)
    for i = 1, images_needed do
    text_image = {  }
    text_image[i] = Image.createEmpty(512, 10)
    text_image[i]:clear(background_colour)
    marquee_string_part = string.sub(marquee_string, (64 * i) - 64, 64 * i)
    text_image[i]:print(0, 1, marquee_string_part, text_colour)
    screen:blit(xpos + (512 * i) - 512, y_position, text_image[i])
    end
    
    if speed > 0 then
    if xpos > 480 then
    xpos = 0 - (string_len)
    end
    elseif speed < 0 then
    if xpos < (0 - string_len) then
    xpos = 480
    end
    end
    
    end
    
    oldpad = Controls.read()
    
    while true do
    
    pad = Controls.read()
    
    screen:clear()
    
    -- insert your main code here
    
    scrolling_marquee("test string for marquee and it is a really long string so it will go off the end of the screen but i am going to test it with lots of images as it will be quick and also it will create the right amount of images for the strings length which is an added bonus so the string can be as long as you want it to be", black, white, 1.2)
    
    -- insert your main code here
    
    if Controls.read():start() then
    	break
    end
    
    oldpad = pad
    
    screen.flip()
    screen.waitVblankStart()
    
    end
    thanks

    [email protected]

    p.s. thanks to eldiablov for suggesting to use images
    Geändert von FaT3oYCG (03-08-2008 um 05:50 AM Uhr)
    ------ FaT3oYCG -----
    AKA Craig, call me what you want to It's your preference.
    My Website: http://www.modern-gamer.co.uk/

    Currently working on:
    (0) MediaGrab
    (0) PGE Gears Of War - On hold (Very large project).
    (0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).

  18. #138
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    resize image function

    this function resizes an image to the maximum size that you set, if you want the image to be smaller than 100 width or height and you dont know which is bigger on the image it wont matter it works it out for you

    how it woks
    you input the image you want to use and the maximum size
    it then works out weather the height or width is larger
    it then takes an aspect ratio based on that
    it then makes the larger size width or height the maximum size you requested
    it then makes the other width or height relevant to that based on the aspect ratio

    usage
    Code:
    my_resized_image = resize_image(Image.load("picture.png", 200)
    
    screen:blit(10, 10, my_resized_image)
    the code
    Code:
    white = Color.new(255, 255, 255)
    
    function resize_image(the_image, max_size)
    
    image_height = the_image:height()
    image_width = the_image:width()
    
    	if image_height ~= max_size or image_width ~= max_size then
    
    		if image_width > image_height then
    			resize_type = width
    			image_aspect = (image_width / image_height)
    		elseif image_width < image_height then
    			resize_type = height
    			image_aspect = (image_height / image_width)
    		elseif image_width == image_height then
    			resize_type = width
    			image_aspect = (image_width / image_height)
    		end
    
    		if resize_type == width then
    			new_image_width = max_size
    			new_image_height = max_size / image_aspect
    		elseif resize_type == height then
    			new_image_height = max_size
    			new_image_width = max_size / image_aspect
    		end
    
    	scaled_image = Image.createEmpty(new_image_width, new_image_height)
    
    		for x = 1, new_image_width do
    			for y = 1, new_image_height do
    				scaled_image:blit(x,y , the_image, math.floor(x*(the_image:width()/new_image_width)), math.floor(y*(the_image:height()/new_image_height)),1,1)
    			end
    		end
    
    		return scaled_image
    	else
    		return the_image
    	end
    end
    
    oldpad = Controls.read()
    
    while true do
    
    pad = Controls.read()
    
    screen:clear()
    
    -- insert your main code here
    
    an_image = resize_image(Image.load("picture.png"), 100)
    
    screen:print(10, 10, an_image:width(), white)
    screen:print(10, 20, an_image:height(), white)
    screen:blit(10, 40, an_image)
    
    -- insert your main code here
    
    if Controls.read():start() then
    	break
    end
    
    oldpad = pad
    
    screen.flip()
    screen.waitVblankStart()
    
    end
    EDIT:

    i just changed this line

    Code:
    if image_height > max_size or image_width > max_size then
    to this

    Code:
    if image_height ~= max_size or image_width ~= max_size then
    so it can make images smaller or larger
    Geändert von FaT3oYCG (04-06-2008 um 07:04 AM Uhr)
    ------ FaT3oYCG -----
    AKA Craig, call me what you want to It's your preference.
    My Website: http://www.modern-gamer.co.uk/

    Currently working on:
    (0) MediaGrab
    (0) PGE Gears Of War - On hold (Very large project).
    (0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).

  19. #139
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    ok im here again with another sample, before anyone says no i didn't copy any of it and no i did not use any examples the only thing i had to look up was the table.remove function that i have used from the lua users wiki, other than that i spent quite a while creating the priority system, it is useful for more things than this but adding it to this is one of the main features

    ok so i know now your asking what the hell has he made, well i have made ...

    a windowing system, it mixes a nice looking interface with speed and control

    ok so here is the code

    Code:
    white = Color.new(255, 255, 255)
    black = Color.new(0, 0, 0)
    red = Color.new(255, 0, 0)
    green = Color.new(0, 255, 0)
    blue = Color.new(0, 0, 255)
    orange = Color.new(235, 115, 0)
    yellow = Color.new(255, 255, 0)
    ubuntu_brown = Color.new(220, 170, 130)
    
    windows = { }
    duplicate_window_number = 0
    
    function create_window(window_x, window_y, window_width, window_height, window_title)
    	for i = 1, table.getn(windows) do
    		if windows[i].title == window_title then
    			duplicate_window_number = duplicate_window_number + 1
    			window_title = window_title .. " (" .. duplicate_window_number .. ")"
    		end
    	end
    	window_number = table.getn(windows) + 1
    	windows[window_number] = { x = window_x, y = window_y, width = window_width, height = window_height, title = window_title, old_width = window_width, old_height = window_height, old_x = window_x, old_y = window_y, priority = table.getn(windows) + 1, state = 1 }
    	
    	-- create window images
    	window_outline = Image.createEmpty(windows[window_number].width, windows[window_number].height)
    	window_background = Image.createEmpty(windows[window_number].width - 2, windows[window_number].height - 2)
    	window_bar = Image.createEmpty(windows[window_number].width - 4, 10)
    	window_main = Image.createEmpty(windows[window_number].width - 4, windows[window_number].height - 15)
    	-- create window images
    
    	-- colour window images
    	window_outline:clear(black)
    	window_background:clear(ubuntu_brown)
    	window_bar:clear(white)
    	window_main:clear(white)
    	-- colour window images
    
    	-- display window title
    	window_bar:print(1, 1, windows[window_number].title, black)
    	-- display window title
    
    	-- blit window images to the main image
    	window_background:blit(1, 1, window_bar)
    	window_background:blit(1, 12, window_main)
    	window_outline:blit(1, 1, window_background)
    	-- blit window images to the main image
    
    	-- create the window image in that windows table
    	windows[window_number].image = window_outline
    	-- create the window image in that windows table
    end
    
    function refresh_window(window_number)
    	-- create window images
    	window_outline = Image.createEmpty(windows[window_number].width, windows[window_number].height)
    	window_background = Image.createEmpty(windows[window_number].width - 2, windows[window_number].height - 2)
    	window_bar = Image.createEmpty(windows[window_number].width - 4, 10)
    	window_main = Image.createEmpty(windows[window_number].width - 4, windows[window_number].height - 15)
    	-- create window images
    
    	-- colour window images
    	window_outline:clear(black)
    	window_background:clear(ubuntu_brown)
    	window_bar:clear(white)
    	window_main:clear(white)
    	-- colour window images
    
    	-- display window title
    	window_bar:print(1, 1, windows[window_number].title, black)
    	-- display window title
    
    	-- blit window images to the main image
    	window_background:blit(1, 1, window_bar)
    	window_background:blit(1, 12, window_main)
    	window_outline:blit(1, 1, window_background)
    	-- blit window images to the main image
    
    	-- create the window image in that windows table
    	windows[window_number].image = window_outline
    	-- create the window image in that windows table
    end
    
    function display_windows()
    	for i = 1, table.getn(windows) do
    		if windows[i].state ~= 0 then
    			screen:blit(windows[i].x, windows[i].y, windows[i].image)
    		end
    	end
    end
    
    function minimize_all_windows()
    	for i = 1, table.getn(windows) do
    		windows[i].state = 0
    	end
    end
    
    function minimize_window(number)
    	windows[number].state = 0
    end
    
    function maximize_window(number)
    	if windows[number].state ~= 2 then
    		windows[number].old_x = windows[number].x
    		windows[number].old_y = windows[number].y
    		windows[number].old_width = windows[number].width
    		windows[number].old_height = windows[number].height
    		windows[number].state = 2
    		windows[number].x = 0
    		windows[number].y = 20
    		windows[number].width = 480
    		windows[number].height = 232
    		refresh_window(number)
    	end
    end
    
    function restore_window(number)
    	if windows[number].state ~= 1 then
    		windows[number].state = 1
    		windows[number].x = windows[number].old_x
    		windows[number].y = windows[number].old_y
    		windows[number].width = windows[number].old_width
    		windows[number].height = windows[number].old_height
    		refresh_window(number)
    	end
    end
    
    function change_priority(window)
    	temp = { }
    	for i = 1, table.getn(windows) do
    		temp[i] = windows[i]
    	end
    	windows[1] = windows[window]
    	for i = 2, table.getn(windows) + 1 do
    		windows[i] = { }
    		windows[i] = temp[i - 1]
    	end
    	table.remove(windows, window + 1)
    end
    
    oldpad = Controls.read()
    
    while true do
    
    pad = Controls.read()
    
    screen:clear(white)
    
    -- insert your main code here
    
    if pad:cross() and not oldpad:cross() then
    	create_window(10, 10, 300, 200, "title")
    end
    
    display_windows()
    
    if pad:up() then
    	windows[table.getn(windows)].y = windows[table.getn(windows)].y - 3
    elseif pad:down() then
    	windows[table.getn(windows)].y = windows[table.getn(windows)].y + 3
    elseif pad:left() then
    	windows[table.getn(windows)].x = windows[table.getn(windows)].x - 3
    elseif pad:right() then
    	windows[table.getn(windows)].x = windows[table.getn(windows)].x + 3
    end
    
    if pad:triangle() and not oldpad:triangle() then
    	change_priority(table.getn(windows))
    end
    
    -- insert your main code here
    
    if Controls.read():start() then
    	break
    end
    
    oldpad = pad
    
    screen.flip()
    screen.waitVblankStart()
    
    end
    yeah there is a lot, i added lots of functions so you can play around with them if you like, if you know what one of my main current projects is then you will understand the reason why i made this

    now this took quite a while to make and i had to do a lot of recoding to get things to work so i would greatly appreciate that you credit me if you use this

    -- functions
    create_window() creates a window, the arguments are x position, y position, width, hight, and the title for that window
    refresh_window() clears the window of all data inside the main box, the argument is the window to refresh
    display_windows() does what it says and displays all of the windows if their state is right
    minimize_all_windows() sets all of the windows states to 0 so that they are all minimized in effect
    minimize_window() minimizes the window selected, the argument is the number of the window to minimize
    maximize_window() makes the window full screen, the argument is the window to maximize
    restore_window() makes the window return to the size it was before minimized or maximized

    -- putting data in a window

    to put data in a window use this method

    Code:
    window[number].image:print(3, 18, "data")
    - i will make a function to do this so it is easier to use


    thanks

    [email protected]

    - p.s. works on lua player windows

    - p.s.s adding explanations of the functions and how to put data in a window

    - p.s.s.s i reserve the right to change or add to this code at any time
    Geändert von FaT3oYCG (04-11-2008 um 03:36 PM Uhr)
    ------ FaT3oYCG -----
    AKA Craig, call me what you want to It's your preference.
    My Website: http://www.modern-gamer.co.uk/

    Currently working on:
    (0) MediaGrab
    (0) PGE Gears Of War - On hold (Very large project).
    (0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).

  20. #140
    QJ Gamer Green
    Points: 5.889, Level: 49
    Level completed: 70%, Points required for next Level: 61
    Overall activity: 0%

    Registriert seit
    Nov 2007
    Beiträge
    918
    Points
    5.889
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    someone needs to update the first post so that it is easier to find the scripts, i had to look through about 8 pages to find the script that i couldnt think of the name or what it did, but i knew it would help me
    My Projects
    [URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
    working on Zuno, an uno like game
    [QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]

  21. #141
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    set pagination to 50
    ctrl+f

  22. #142
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    ifiwere1337 - Everyone knows to set the posts p/page to 40 (i believe that's the max) then use any find-feature in your browser...

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  23. #143
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von SG57
    ifiwere1337 - Everyone knows to set the posts p/page to 40 (i believe that's the max) then use any find-feature in your browser...
    yeah if you do that then you get about 4 pages for this thread in total - to make sure i get the max i chose custom and put 99 but it doesn't actually show 99 ppp
    ------ FaT3oYCG -----
    AKA Craig, call me what you want to It's your preference.
    My Website: http://www.modern-gamer.co.uk/

    Currently working on:
    (0) MediaGrab
    (0) PGE Gears Of War - On hold (Very large project).
    (0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).

  24. #144
    QJ Gamer Green
    Points: 5.889, Level: 49
    Level completed: 70%, Points required for next Level: 61
    Overall activity: 0%

    Registriert seit
    Nov 2007
    Beiträge
    918
    Points
    5.889
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von SG57
    ifiwere1337 - Everyone knows to set the posts p/page to 40 (i believe that's the max) then use any find-feature in your browser...
    the thing is that i forgot what it was called or what it did, but i knew i could use it, so i couldnt search for it, where is the ppp setting?
    My Projects
    [URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
    working on Zuno, an uno like game
    [QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]

  25. #145
    Developer and Tutor.
    Points: 8.736, Level: 62
    Level completed: 96%, Points required for next Level: 14
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Ort
    Widnes, England
    Beiträge
    1.649
    Points
    8.736
    Level
    62
    My Mood
    Happy
    Downloads
    0
    Uploads
    0

    Standard

    in user cp under options i think

    EDIT:

    here

    user cp

    - edit options

    -- thread display options

    --- Number of Posts to Show Per Page
    ------ FaT3oYCG -----
    AKA Craig, call me what you want to It's your preference.
    My Website: http://www.modern-gamer.co.uk/

    Currently working on:
    (0) MediaGrab
    (0) PGE Gears Of War - On hold (Very large project).
    (0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).

  26. #146
    QJ Gamer Green
    Points: 5.889, Level: 49
    Level completed: 70%, Points required for next Level: 61
    Overall activity: 0%

    Registriert seit
    Nov 2007
    Beiträge
    918
    Points
    5.889
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von FaT3oYCG
    in user cp under options i think

    EDIT:

    here

    user cp

    - edit options

    -- thread display options

    --- Number of Posts to Show Per Page
    thanks nowi got it
    My Projects
    [URL="http://www.megaupload.com/?d=Q860B1VV"]BUMPER HARVEST MOD - PEGGLE DELUXE BETA 1[/URL]
    working on Zuno, an uno like game
    [QUOTE=FreePlay]It's a picture of a monkey. There, I spoiled it for you.[/QUOTE]

  27. #147
    QJ Gamer Blue
    Points: 4.268, Level: 41
    Level completed: 59%, Points required for next Level: 82
    Overall activity: 0%

    Registriert seit
    Apr 2008
    Beiträge
    497
    Points
    4.268
    Level
    41
    Downloads
    0
    Uploads
    0

    Standard

    no one posts here any more it's been almost a month since anyone added anything to the thread

  28. #148
    QJ Gamer Green
    Points: 3.721, Level: 38
    Level completed: 48%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Jan 2008
    Beiträge
    612
    Points
    3.721
    Level
    38
    Downloads
    0
    Uploads
    0

    Standard

    so? people are tired of handing out their code that they WORKED to create to noobs who copy and paste it and complain when it doesn't work.

  29. #149
    QJ Gamer Blue
    Points: 4.268, Level: 41
    Level completed: 59%, Points required for next Level: 82
    Overall activity: 0%

    Registriert seit
    Apr 2008
    Beiträge
    497
    Points
    4.268
    Level
    41
    Downloads
    0
    Uploads
    0

    Standard

    Hey!! I wasn't saying people had to just hand out there code, don't get so defensive, I was just noticeing, how this thread isn't being used, and so there should be a thread here that isused, instead. I wasn't saying that I want to take anyones, code or anything. I don't steal code like that and call it my own!!

  30. #150
    QJ Gamer Bronze
    Points: 8.665, Level: 62
    Level completed: 72%, Points required for next Level: 85
    Overall activity: 0%

    Registriert seit
    Mar 2007
    Beiträge
    758
    Points
    8.665
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    There's already 8 pages (20 post per page) of post, and the first post is absolutely massive, don't you think that's enough to learn from?


 
Seite 5 von 7 ErsteErste 1 2 3 4 5 6 7 LetzteLetzte

Tags for this Thread

Forumregeln

  • Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
  • Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
  • Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
  • Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
  •  





Alle Zeitangaben in WEZ -8. Es ist jetzt 09:07 PM Uhr.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © , Caputo Media, LLC. All Rights Reserved. Cluster .