Results 1 to 10 of 10

Thread: More code help (control problem)

                  
   
  1. #1
    DCEmu Legend gunntims0103's Avatar
    Join Date
    May 2006
    Location
    Brentwood, NY
    Age
    33
    Posts
    2,976
    Rep Power
    108

    Default More code help (control problem)

    Im having 2 very big problems and untill they are solved i cant progress.

    -1st problem

    It seems that the sprites are not blit to the screen for the whole time it only stay on for a mili second then goes away. This happenes from the transition from the menu.lua to the scene.lua. where the text from the menu.lua stays on the screen when the scene.lua is initiated. The scene.lua only blits the sprites for a short time then goes away. why its doing this i have no idea.

    Code from menu.lua
    Code:
    status = "menu"
    
    Black = Color.new(0, 0, 0)
    Red = Color.new(255, 0, 0)
    
    --load images--
    Background = Image.load("backgrounds/menu.png")
    
    --load files--
    LoadA = loadfile("scene.lua")
    LoadB = loadfile("instructions.lua")
    LoadC = loadfile("credits.lua")
    
    while true do
    
    current = 1
    oldpad = Controls.read()
    
    while true do
    
    pad = Controls.read()
    screen:clear()
    
    ----prints to the screen-------
    screen:blit(0, 0, Background)
    screen:print(185, 175, "Start Game", Black)
    screen:print(185, 195, "Instructions", Black)
    screen:print(185, 215, "Credits", Black)
    screen:print(314, 263, "Press Home to exit", Black)
    screen:print(320, 4, "Gunntims0103-Coder", Black)
    
    -----this code is so that when you highlight an option in a menu it turns red-----
    if current == 1 then
    screen:print(185, 175, "Start Game", Red)
    end
    
    if current == 2 then
    screen:print(185, 195, "Instructions", Red)
    end
    
    if current == 3 then
    screen:print(185, 215, "Credits", Red)
    end
    
    -----this makes it so that you can scroll through your menu----
    if pad:up() and oldpad:up() ~= pad:up() then
    current = current-1
    end
    
    if pad:down() and oldpad:down() ~= pad:down() then
    current = current+1
    end
    
    if current == 4 then
    current = 1
    end
    
    if current == 0 then
    current = 3
    end
    
    -----this is to select your menu options------
    if pad:cross() and current == 1 then
    LoadA()
    end
    
    if pad:cross() and current == 2 then
    LoadB()
    end
    
    if pad:cross() and current == 3 then
    LoadC()
    end
    
    screen.waitVblankStart()
    screen:flip()
    oldpad = pad
    
    end
    
    end
    Code from scene.lua
    Code:
    Black = Color.new(0, 0, 0)
    
    --load images, this is for the cutscene--
    Background = Image.load("backgrounds/scene1.png")
    Sora = Image.load("sprites/sora.png")
    Enemie = Image.load("sprites/enemie.png")
    Talk = Image.load("sprites/talk.png")
    
    --load files--
    LoadA = loadfile("menu.lua")
    
    pad = Controls.read()
    screen:clear()
    
    --prints to screen--
    screen:blit(0, 0,Background)
    screen:blit(31, 230,Sora)
    screen:blit(330, 230,Enemie)
    screen:blit(35, 30,Talk)
    
    if pad:cross() then
    LoadA()
    
    Screen:waitVblankStart()
    Screen:flip()
    end
    -2nd problem

    Also another problem that i am having is that the credits.lua and the instructions.lua are not initiated when picked from the menu. how do i fix this

    Code from credits.lua
    Code:
    black = Color.new(0, 0, 0)
    
    
    background = Image.load("backgrounds/credits.png")
    loadA = loadfile("menu.lua")
    
    while true do
    
    pad = Controls.read()
    screen:blit(0, 0, background)
    
    if pad:cross() then
    loadA()
    end
    
    screen.waitVblankStart()
    screen:flip()
    end
    Code from instructions.lua
    Code:
    black = Color.new(0, 0, 0)
    
    
    background = Image.load("backgrounds/instructions.png")
    loadA = loadfile("menu.lua")
    
    while true do
    
    pad = Controls.read()
    screen:blit(0, 0, background)
    
    if pad:cross() then
    loadA()
    end
    
    screen.waitVblankStart()
    screen:flip()
    end
    Well basically i want to be able to eliminate the text that shows up on the scene.lua. I want to have the sprite blit to the screen perminitly. I also want to be able to go into the credits and instructions.lua from the menu

    any help would be much apprecaiated, thank you

  2. #2
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    83

    Default

    In menu.lua you have this line:
    if pad:cross() and current == 1 then LoadA() end

    In scene.lua you have this:
    if pad:cross() then LoadA() end

    When you press Cross in menu.lua, in the next frame, unless you are VERY quick at releasing Cross, it will detect as Cross being pressed and load menu.lua again which in the next frame checks if Cross is pressed and then loads scene.lua again etc

  3. #3
    DCEmu Legend gunntims0103's Avatar
    Join Date
    May 2006
    Location
    Brentwood, NY
    Age
    33
    Posts
    2,976
    Rep Power
    108

    Default

    Quote Originally Posted by yaustar View Post
    In menu.lua you have this line:
    if pad:cross() and current == 1 then LoadA() end

    In scene.lua you have this:
    if pad:cross() then LoadA() end

    When you press Cross in menu.lua, in the next frame, unless you are VERY quick at releasing Cross, it will detect as Cross being pressed and load menu.lua again which in the next frame checks if Cross is pressed and then loads scene.lua again etc
    what i want to know is how do i stop this from happening. Iv tried to restate the controls but to no luck so i just stop trying could you post the code with the corrections and teach me what the code means etc.. so that i dont make the mistake in the future

  4. #4
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    83

    Default

    Well, until you 'get it' and apply it, the easiest solution is to use a different button for menu.lua.

    I use the button check concept in these snippets:
    http://www.dcemu.co.uk/vbulletin/showthread.php?t=28021
    http://www.dcemu.co.uk/vbulletin/showthread.php?t=31982

  5. #5
    DCEmu Legend gunntims0103's Avatar
    Join Date
    May 2006
    Location
    Brentwood, NY
    Age
    33
    Posts
    2,976
    Rep Power
    108

    Default

    Alright so what i do is eather assign different controls for the menu.lua to the scene.lua. so that way its not going from the menu.lua to the scene.lua in rapid concetion.

    or i could use the bool controls code so that it knows that when you press the button and release it that it sould go to only one .lua without going through them rapidly as if you were holding down a control

    sorry if that doesnt make any sence^

  6. #6
    DCEmu Legend gunntims0103's Avatar
    Join Date
    May 2006
    Location
    Brentwood, NY
    Age
    33
    Posts
    2,976
    Rep Power
    108

    Default

    Ok thanx to ninja9393's help i have successfully got the sprites to blit to the screen perminatly. I have also eliminated the text that stays on the screen from the menu.lua to the scene.lua. Also the credits and instructions options now work fine.

    now i will implament the talk sprites every time you press X the old sprite will get cleared and a new one will be blit in the same position. The only problem is i dont know how to go about doing this

    any ideas would be great i have one

    -- a hypethetical code--

    while true do

    if pad:cross then
    --the sprite:clear is a hypethetical code that i will use to clear the old sprite off the screen--
    Sprite:clear
    screen:blit(#, #,Talk)
    end

    --end of code--

    could this actaually work???

  7. #7
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    83

    Default

    No, as the sprite will only display as long as cross is pressed. As soon as it is released, it disappears.

  8. #8
    DCEmu Legend gunntims0103's Avatar
    Join Date
    May 2006
    Location
    Brentwood, NY
    Age
    33
    Posts
    2,976
    Rep Power
    108

    Default

    Quote Originally Posted by yaustar View Post
    No, as the sprite will only display as long as cross is pressed. As soon as it is released, it disappears.
    so the whole problem is to be able to have the code in which after you press X the sprite stays. also you only have to press X once. I understand. I would use the bool_pad:control code for this???

    im unfamiliar with this code yaustar how does it work. please explain

  9. #9
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    83

    Default

    Yes you would to an extent. The whole Bool thing is there to be able to detect the difference between a button press, release and being held down.

    You need another section of code to deal with the conversation graphics. Look up Finite State Machines (FSM). You need to learn how to apply abstract solutions to problems.

  10. #10
    DCEmu Legend gunntims0103's Avatar
    Join Date
    May 2006
    Location
    Brentwood, NY
    Age
    33
    Posts
    2,976
    Rep Power
    108

    Default

    Ninja9393 and i have found a new way to tackle the problem. WE will use images and every time you press X a new image will appear giving the effect of characters talking. Instead of every time you press X a new talk sprite blits to the screen and the old one gets cleared. It would have been nice to do it that way but we dont have the coding knowledge to do it. so were going a bit more simple

    also we will make the last image of the conversation fade into the actual game play

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •