Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Procedures in the GUI
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Wilcroft




PostPosted: Fri Apr 18, 2008 4:42 pm   Post subject: Procedures in the GUI

I'm looking for some assistance.

I'm trying right now to build a game for G11, and I'm basically writing a build screen for attributes and whatnot, using the GUI. I (from what I've read/experience) realize that the GUI is not great, but due to time constraints, etc. I can't write my own.

Here's my basic problem. I want to have one or two procedures that work for all attributes, but in the GUI.CreateButton call, the procedure field doesn't seem to accept parameters. Is this just me, or is this the GUI?

here's my basic code:
Turing:
import GUI
type shipdata :
    record
        armor : int
        shield : int
        laser : boolean
        laserstr : int
        missle : boolean
        misslenum : int
        fighters : boolean
        hangers : int
        scanrange : int
        speed : int
        size : int
        pointdef : boolean
        pdstrength : int
    end record

var p1ships : flexible array 1 .. 1 of shipdata
var total:=20

p1ships (1).armor := 0

proc add %(var num : int)
    p1ships (1).armor += 1
    total-=1
    if total <0 then
    total +=1
    p1ships (1).armor -=1
    end if
    Text.Locate (2, 3)
    put p1ships (1).armor
    put total
end add

var quitButton : int := GUI.CreateButton (10, 10, 0, "Quit", GUI.Quit)
var addarmor := GUI.CreateButton (10, 35, 0, "+1", add )

loop
    exit when GUI.ProcessEvent
end loop


I want to instead change it to add(p1ships(1).armor), so I can use the same procedure for all the variables. Could someone tell me if this is possible, or possibly hook me up with a way to make it work?
Sponsor
Sponsor
Sponsor
sponsor
Nick




PostPosted: Fri Apr 18, 2008 4:54 pm   Post subject: RE:Procedures in the GUI

you can't it's the GUI, however you could make it call a procedure which calls your procedure:

code:
proc this(x,y:int)

end this
proc foo
    this(20,40)
end foo
var addarmor := GUI.CreateButton (10, 35, 0, "+1", foo )
Wilcroft




PostPosted: Fri Apr 18, 2008 5:29 pm   Post subject: Re: Procedures in the GUI

thanks Nick. through your help, and ideas from my dad, I have figured it out using multiple buttons, which was the basis of my problem. I've managed to reduce my procedure count from 16 to 4! Wheee!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: