Computer Science Canada

Barbarien Bashers

Author:  copthesaint [ Mon Jan 05, 2009 3:51 pm ]
Post subject:  Barbarien Bashers

Well I am making this game hoping that this one will run. (all my other programs crash computer because they take up too much ram for a computer to use eg. My Guitarhero)

The problem is that When I run the program I keep clicking GUI buttons that should not exist...

Here is the code (not done)

code:
%Barbarien Bashers
import GUI
View.Set ("graphics:800;600;offscreenonly;nocursor")
var x, y, xc1, yc1, xc2, yc2, xc3, yc3, xc4, yc4, xc5, yc5, xc6, yc6, xc7, yc7, xc8, yc8, xc9, yc9, xc10, yc10, WindowView : int := 0
var fnt1 := Font.New ("Ariel:12x7")
var fnt2 := Font.New ("Ariel:12x7")
var fnt3 := Font.New ("Ariel:12x9")
var fnt4 := Font.New ("Ariel:12x10")
var fnt5 := Font.New ("Ariel:12x11")
var fnt6 := Font.New ("Ariel:12x12")
var fntstrech := 0
var colorText := 160
var Player1 := Pic.FileNew ("Pictures/Player1.jpg")
var Player2 := Pic.FileNew ("Pictures/Player2.jpg")
var drawx := maxx div 100
var drawy := maxy div 100
var chars : array char of boolean
var menumain := 0
procedure Play
    menumain := 3
    GUI.Quit
end Play
procedure Viewchange
    menumain := 3
    GUI.Quit
end Viewchange
procedure Back1
    menumain := 2
    GUI.Quit
end Back1
procedure Sound
    menumain := 3
    GUI.Quit
end Sound
procedure Option
    menumain := 2
    GUI.Quit
end Option
procedure Graphics640_400
    View.Set ("graphics:640;400;offscreenonly;nocursor")
    menumain := 2
    GUI.Quit
end Graphics640_400
procedure Graphics800_600
    View.Set ("graphics:800;600;offscreenonly;nocursor")
    menumain := 2
    GUI.Quit
end Graphics800_600
procedure Graphics1024_768
    View.Set ("graphics:1024;768;offscreenonly;nocursor")
    menumain := 2
    GUI.Quit
end Graphics1024_768
procedure WelcomeScreen
    loop
        Input.KeyDown (chars)
        if menumain = 0 then
            if chars (KEY_ENTER) then
                if menumain = 0 then
                    delay (250)
                    menumain := 1
                end if
            end if
            colorback (16)
            if fntstrech = 1 then
                if colorText > 309 then
                    fntstrech := 0
                end if
                colorText += 1
            elsif fntstrech = 0 then
                if colorText < 171 then
                    fntstrech := 1
                end if
                colorText -= 1
            end if
            Font.Draw ("Press Enter to Start", drawx * 44, drawy * 20, fnt2, colorText div 10)

        elsif menumain = 1 then
            delay (250)
            loop
                cls
                var PlayBUTTON : int := GUI.CreateButtonFull (maxx div 2 - drawx * 7, drawy * 40, drawx * 14, "Play", Play, 0, '^d', true)
                var OptionBUTTON : int := GUI.CreateButtonFull (maxx div 2 - drawx * 7, drawy * 35, drawx * 14, "Options", Option, 0, '^d', true)
                exit when GUI.ProcessEvent
                View.Update
                delay (1)
                GUI.Dispose (PlayBUTTON)
                GUI.Dispose (OptionBUTTON)
            end loop
            GUI.ResetQuit
        elsif menumain = 2 then
            delay (250)
            loop
                cls
                var OptionGraphicsBUTTON : int := GUI.CreateButtonFull (maxx div 2 - drawx * 7, drawy * 40, drawx * 14, "Video", Viewchange, 0, '^d', true)
                var OptionSoundBUTTON : int := GUI.CreateButtonFull (maxx div 2 - drawx * 7, drawy * 35, drawx * 14, "Sound", Sound, 0, '^d', true)
                var OptionBackBUTTON : int := GUI.CreateButtonFull (maxx div 2 - drawx * 7, drawy * 30, drawx * 14, "Back", Back1, 0, '^d', true)
                exit when GUI.ProcessEvent
                View.Update
                delay (1)
                GUI.Dispose (OptionGraphicsBUTTON)
                GUI.Dispose (OptionSoundBUTTON)
                GUI.Dispose (OptionBackBUTTON)
            end loop
            GUI.ResetQuit
        elsif menumain = 3 then
            delay (250)
            loop
                cls
                var OptionGraphicsSet640_400BUTTON : int := GUI.CreateButtonFull (maxx div 2 - drawx * 9, drawy * 40, drawx * 18, "Video(640,400)", Graphics640_400, 0, '^d', true)
                var OptionGraphicsSet800_600BUTTON : int := GUI.CreateButtonFull (maxx div 2 - drawx * 9, drawy * 35, drawx * 18, "Video(800,600)", Graphics800_600, 0, '^d', true)
                var OptionGraphicsSet1024_768BUTTON : int := GUI.CreateButtonFull (maxx div 2 - drawx * 9, drawy * 30, drawx * 18, "Video(1024,768)", Graphics1024_768, 0, '^d', true)
                exit when GUI.ProcessEvent
                View.Update
                delay (1)
                GUI.Dispose (OptionGraphicsSet640_400BUTTON)
                GUI.Dispose (OptionGraphicsSet800_600BUTTON)
                GUI.Dispose (OptionGraphicsSet1024_768BUTTON)
            end loop
            GUI.ResetQuit
        elsif menumain = 4 then
            delay (250)
            loop
                cls
                var OptionSoundOffBUTTON : int := GUI.CreateButtonFull (maxx div 2 - drawx * 9, drawy * 40, drawx * 18, "Sound(OFF)", Graphics640_400, 0, '^d', true)
                var OptionSoundOnBUTTON : int := GUI.CreateButtonFull (maxx div 2 - drawx * 9, drawy * 35, drawx * 18, "Sound(ON)", Graphics800_600, 0, '^d', true)               
                exit when GUI.ProcessEvent
                View.Update
                delay (1)
                GUI.Dispose (OptionSoundOffBUTTON)
                GUI.Dispose (OptionSoundOnBUTTON)
            end loop
            GUI.ResetQuit
        end if
        View.Update
        Time.DelaySinceLast (5)
        cls
    end loop
end WelcomeScreen
procedure GamePlay


end GamePlay

procedure GameOver


end GameOver

loop
    if WindowView = 0 then
        WelcomeScreen
    elsif WindowView = 1 then
        GamePlay
    elsif WindowView = 2 then
        GameOver
    end if
end loop

Author:  DemonWasp [ Mon Jan 05, 2009 4:42 pm ]
Post subject:  RE:Barbarien Bashers

Er, this may be part of your memory problem:
Turing:

loop
   ...
   delay (1)
   GUI.Dispose ( ... )
   GUI.Dispose ( ... )
end loop


If I recall correctly, GUI.Dispose is only for after you're sure you're done with the GUI control in question. What you're doing right now is creating the GUI, checking whether anything clicked on it _that instant_, then disposing of it, only to loop around and create it again immediately.

If you're doing stuff like that, you're going to run into performance issues. Turing may not dispose of the GUI components properly, which could definitely lead to massive memory consumption.

Here's a rule of thumb: if you're running out of memory with Turing, you're doing something very very wrong.

Author:  copthesaint [ Mon Jan 05, 2009 5:28 pm ]
Post subject:  RE:Barbarien Bashers

Did you even test the program at all? and no GUI. dispose is thier because I am creating the button in the loop also. Doing this I can acually make animations in the backround. The problem is just occuring for me for the very first time. I have done the same setup of GUI in the past and it has worked fine.

Author:  Laplace's Demon [ Mon Jan 05, 2009 6:39 pm ]
Post subject:  Re: Barbarien Bashers

The way you have the program set up is inefficient for a number of reasons.

You are creating and then destroying the buttons (theoretically) 1000 times a second, you have a delay of only one millisecond. You do not need to do this, the GUI module creates the buttons in a separate process from your main loop, it runs concurrently (alongside) your main program. What this means for you is that you do not need to check the button 1000 times a second, the button will work no matter how often you go through the loop.

The way you should have it set up is to create the buttons then create a loop BELOW and SEPARATE from the buttons. This way you will create the buttons, then the program will effectively wait until the procedures called by your buttons tells the program to exit the loop. That said, the GUI buttons are generally kind of crummy, try creating your own buttons using Mouse.Where.


EDIT: Your problem is caused by the fact that you are exiting the loop before you use GUI.Dispose. You can not just move exit when GUI.ProcessEvent to the bottom of the loop because the after GUI.Dispose occurs the parameters required for exit when GUI.ProcessEvent are no longer fulfilled. Truly, I would just recommend starting over because the way you have it structured just doesn't work properly and will only cause more issues in the future.

Author:  DemonWasp [ Tue Jan 06, 2009 10:04 am ]
Post subject:  RE:Barbarien Bashers

What you should be doing looks like this:

1. Set up GUI controls
2. Loop, checking GUI.ProcessEvent and running animations. Increase your delay a little, 1ms is incredibly short. Try something like 10ms (100fps) or maybe 16 (60fps, the most that most screens can draw).
3. After the loop, destroy the GUI controls.

Author:  copthesaint [ Tue Jan 06, 2009 3:30 pm ]
Post subject:  RE:Barbarien Bashers

Thanks everyone but I had already solved to problem on my own time. (Reason for adding GUI to loop: Thought that GUI.Dispose would work... Also this way I can do animations in the backround)

Thanks people but i had figured it out. (Not posting code again)

Author:  copthesaint [ Tue Jan 13, 2009 3:33 pm ]
Post subject:  Re: Barbarien Bashers

I'm Getting further and further to finishing my game (still a long way to go...)
Here is what I have done so far!
Please tell me what you think

Author:  copthesaint [ Mon Jan 19, 2009 3:20 pm ]
Post subject:  Re: Barbarien Bashers

This is an update with code.
I need help because whenever you attempt to open the writen variables, You will get an error:
(String passed to "strint" is not in correct format) Can someone help me?

Author:  saltpro15 [ Mon Jan 19, 2009 3:48 pm ]
Post subject:  RE:Barbarien Bashers

The error I get is that your program was dividing by zero, you need an elsif to check for that

Author:  TheGuardian001 [ Mon Jan 19, 2009 10:16 pm ]
Post subject:  Re: Barbarien Bashers

Ah. you wanted us to hit continue to get that error. probably should have said that. pressing new game brings up the aforementioned error of divided by 0, which you might also want to look into.

on to the error you mentioned.
is there any reason you store all of the stats on the same line? if you store them all on their own lines, it is only possible to get one value at a time, which removes some of the complexity of loading it. I believe doing this also fixes the error, although I have no idea why this error comes up or how this fixes it, but it works.

Author:  copthesaint [ Tue Jan 20, 2009 3:28 am ]
Post subject:  RE:Barbarien Bashers

u guys don't worrie bout that its cause u need to press s at map need inrease stats i want to know why i can't continue with strint error

Author:  andrew. [ Tue Jan 20, 2009 7:59 am ]
Post subject:  RE:Barbarien Bashers

Maybe the string isn't a valid integer. Try using strintok to check if the string can successfully be converted.

Author:  copthesaint [ Tue Jan 20, 2009 12:00 pm ]
Post subject:  RE:Barbarien Bashers

... Does anyone just have a sucsessfull program that writes and gets files? My teacher doesn't know what to do to help me and I'm already doing things that arn't supposed to be taught

Author:  copthesaint [ Wed Jan 21, 2009 3:05 pm ]
Post subject:  RE:Barbarien Bashers

OK I found out on my own that when saveing files you can't use write only put

Author:  Clayton [ Wed Jan 21, 2009 4:47 pm ]
Post subject:  RE:Barbarien Bashers

Turing:
var stream : int
open : stream, "testfile.txt", write
write : stream, "Hello"
close : stream

var foo : string
open : stream, "testfile.txt", read
read : stream, foo
put foo

Author:  DemonWasp [ Thu Jan 22, 2009 9:38 am ]
Post subject:  RE:Barbarien Bashers

As I recall, using put and get means "output and input are both in ASCII", whereas using write and read means "output and input are both in binary".

I could be wrong though.

Author:  copthesaint [ Thu Jan 22, 2009 11:25 am ]
Post subject:  RE:Barbarien Bashers

Sorry I didn't mean that you "couldn't" It's just The way I was doing it I had to use put instead of write


: