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

Username:   Password: 
 RegisterRegister   
 i need some help on procedures with button
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ViRuAl_InFeCtiON_vErsIonX




PostPosted: Mon Jul 04, 2005 4:12 pm   Post subject: i need some help on procedures with button

i just need some help understanding how this example from turing help works Confused

procedure greetings
put "Hello world"
end greetings

greetings % This outputs Hello world

procedure sayItAgain ( msg : string, n : int )
for i : 1 .. n
put msg
end for
end sayItAgain

sayItAgain ("Toot", 2 ) % Toot is output twice

procedure double ( var x : real )
x := 2 * x
end double

var y : real := 3.14
double ( y ) % This doubles the value of y

what each of them mean and if i where going to put button how i would declare them thanks alot poeple Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Mon Jul 04, 2005 6:50 pm   Post subject: (No subject)

1)
Please use [code] or [syntax] tags.

2)
Please learn to use some grammar, for all our sakes. Spelling, on the other hand, is not as big of a deal.

3)
If by 'button' you are referring to the GUI. button then you will find out how to use it in the same place you found those examples. Basically, you'll be creating an integer stream for the GUI to reference across, a related procedure (such as those examples) and some other paramters (locational and the like).
You get something like:
Turing:

procedure test
    put "Testing!"
end test

var myButton : int
myButton := GUI.CreateButton (100, 100, 90, "Click!", test)

loop
   exit when GUI.ProcessEvent
end loop
[Gandalf]




PostPosted: Mon Jul 04, 2005 8:36 pm   Post subject: (No subject)

Also, please try to keep all of your procedures and functions together - usually somewhere near the top of the program.
Cervantes




PostPosted: Mon Jul 04, 2005 9:48 pm   Post subject: (No subject)

We've got a Turing tutorial regarding subroutines.

If you don't understand the basics behind subroutines (such as procedures and functions) you may want to try to tracing execution. In Turing, select the run menu, then select Show Debugger Menu. Select the newly unveiled debugger menu and select show debugger controls. Select Trace Execution and select a speed. Execute the program.

If you are wondering about passing parameters, it's relatively simple. If a procedure has parameters, then when you call the procedure you must specify the correct number and type of parameters. For example, if I make a greet procedure, like this:
code:

procedure Greet (name : string)
    put "Hello ", name
end Greet

then I must call it by passing in a single parameter that is a string, like so:
code:

Greet ("Charlie Parker")

This would output:
code:
Hello Charlie Parker

If a subroutine has more than one parameter, then the values are associated by the order in which they appear.
code:

procedure Greet (first_name : string, last_name : string)
     put "Greetings and salutations ", first_name, " ", last_name, "."
end Green

Now, we must pass in two values. Inside the procedure, first_name and last_name act as local variables (local in the sense that they do not exist outside the procedure) that are initialized as the values passed in at the procedure call.
code:

Greet ("Charlie", "Parker")

first_name is a string that has a value of "Charlie" and last_name is a string that has a value of "Parker". The output is
code:

Greetings and salutations Charlie Parker.
MysticVegeta




PostPosted: Tue Jul 05, 2005 11:11 am   Post subject: (No subject)

Delos wrote:
1)
Please use [code] or [syntax] tags.

2)
Please learn to use some grammar, for all our sakes. Spelling, on the other hand, is not as big of a deal.

3)
If by 'button' you are referring to the GUI. button then you will find out how to use it in the same place you found those examples. Basically, you'll be creating an integer stream for the GUI to reference across, a related procedure (such as those examples) and some other paramters (locational and the like).
You get something like:
Turing:

procedure test
    put "Testing!"
end test

var myButton : int
myButton := GUI.CreateButton (100, 100, 90, "Click!", test)

loop
   exit when GUI.ProcessEvent
end loop


you forgot

[code]import GUI[/code]

This goes in the beginning.
ViRuAl_InFeCtiON_vErsIonX




PostPosted: Tue Jul 05, 2005 5:52 pm   Post subject: another question

alright thanks alot

one more question is there a way i could fork it?
like

var site1 : array 1..2 of string := init ("http://www.google.com","http://www.google.com")
var site1 : array 1..2 of string := init ("http://www.miniclips.com","http://www.google.com")
process web ( word : string := init )
loop
if Sys.Exec (site (Rand.Int(1,upper(site)))) then
end if
if Sys.Exec (site1 (Rand.Int(1,upper(site1)))) then
end if
end loop
end web

fork site
fork site1
% trying to fork this process
ViRuAl_InFeCtiON_vErsIonX




PostPosted: Tue Jul 05, 2005 6:52 pm   Post subject: (No subject)

i was also wondering how in a program can u make random windows in the scrren pop up ? i was trying to make this work based on turing help

var winID : int
var x, y, clr : int

winID := Window.Open ("position:top;center,graphics:200;200")


var x, y, clr : int
for : 1 .. 20
x := Rand.Int (0, maxx)
y := Rand.Int (0, maxy)
clr := Rand.Int (0, maxcolor)
winId (x, y, 30, 30, clr)
end for

var ch : char := getchar

Window.Close (winID)
it was used for filling a window full of random circles but i was wondering if i can make fill the screen with windows or make like 2 or 3 windows that will pop up
Delos




PostPosted: Tue Jul 05, 2005 7:39 pm   Post subject: (No subject)

It would really help if you read all the posts before you posted again. This is your second warning by myself to use [code] or [syntax] tags. Not a good way to be going.
And double posting is also something you should refrain from doing. There's a little button called 'Edit' that will serve your purposes.

By looking at your code, I get the feeling you're trying to make some sort of annoying pop-up creation. If so, don't even think about posting it here. You won't get good reviews. (Actually, it will be deleted pretty quickly).

To answer your questions:
- to fork a process, you need processes! Anything you want forked ought to be enclosed in a process...end process. That being said, processes are bad and should be avoided at all costs unless you're willing to delve into priorities and concurrency.

- to make a new window...consult the Window. tutorial. You will find it in the Tutorials section. If you can't find it, look under Cervantes' Walk-Through, it will have a link to it.
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Tue Jul 05, 2005 8:57 pm   Post subject: (No subject)

Yeah, it seems to me like he ignored a good portion of those posts... And those programs have the looks of martin's "virus ideas" Confused.

Look, basically processes have the effect of working simultaeously, but they do not, and are not recommended. Look into procedures if anything.

For either of the two, you have to know that you must keep the name of the procedure/process the same as what you are forking and/or ending. Obviously. I have no idea why you are naming a process "web" and then forking an array??
MysticVegeta




PostPosted: Wed Jul 06, 2005 3:02 pm   Post subject: (No subject)

ViRuAl_InFeCtiON_vErsIonX wrote:
i was also wondering how in a program can u make random windows in the scrren pop up ? i was trying to make this work based on turing help

var winID : int
var x, y, clr : int

winID := Window.Open ("position:top;center,graphics:200;200")


var x, y, clr : int
for : 1 .. 20
x := Rand.Int (0, maxx)
y := Rand.Int (0, maxy)
clr := Rand.Int (0, maxcolor)
winId (x, y, 30, 30, clr)
end for

var ch : char := getchar

Window.Close (winID)
it was used for filling a window full of random circles but i was wondering if i can make fill the screen with windows or make like 2 or 3 windows that will pop up


hehehe, i made that program when i was nwe to turing,
code:
var win : int
loop
    win := Window.Open ("graphics:" + intstr (Rand.Int (-50, 50)) + "," + intstr (Rand.Int (-50, 50)))
    exit when hasch
end loop


Well, remove the exit when and your mission is accomplished Wink
ViRuAl_InFeCtiON_vErsIonX




PostPosted: Wed Jul 06, 2005 4:21 pm   Post subject: (No subject)

Alright im sorry that i didnt put my turing question in that code you where talking about its just that alot of people do the exact same thing that i was doing so i thought that it was ok i didnt know my bad. and yea i do mess up my spelling but thanks, but for that tip on the edit button i didnt know that i havent been on this site as much as you im a newb. O yea thanks MysticVegeta for that code it was amusing and no i am not trying to make a virus at all are u crazy? lol Laughing And how do i know when to use that code u where talking about because the codes i put on my forum seemed pretty small to me i have seen bigger codes on this site and no one said anything so i was wondering why i am getting in trouble for it. Confused Confused Confused
and could you show me how i should properly use that code you where talking about so i dont get introuble from you? thanks

and i have attached a file. In this file there is one thing that i do not understand is why it says ( word : string) it is in my progam and if any one can tll me what it does and why its there that would be help full also if some could comment that part to help me fully understand the reason why this program needs that part of the code that someone sent to me. Thank you Very Happy



need to understand.t
 Description:

Download
 Filename:  need to understand.t
 Filesize:  243 Bytes
 Downloaded:  109 Time(s)


need to understand.t
 Description:

Download
 Filename:  need to understand.t
 Filesize:  243 Bytes
 Downloaded:  96 Time(s)

Cervantes




PostPosted: Wed Jul 06, 2005 5:06 pm   Post subject: (No subject)

word is a parameter to the process. The : string says that word must be a string. I explained parameters a bit several posts up. Combined with the link I provided you with before I explained them, I think you should be able to use them effectively, let alone understand them. Have you read either of those things?
MysticVegeta




PostPosted: Thu Jul 07, 2005 11:26 am   Post subject: (No subject)

Ok, i read your pm, so i will clear this for everyone who wont understand. lets break the code down.
code:
var win : int
loop
end loop

Self-explainatory.
New window variable
code:
win := Window.Open ("graphics:" + intstr (Rand.Int (-50, 50)) + "," + intstr (Rand.Int (-50, 50)))


Ok, now the variable is assigned to open a window. Now usually you would open a window like this:
code:
win := Window.Open ("graphics:max, max")


We could use any parameters but what that will do is open the window of only 1 size, so the person wont be amused.

Instead, why not make it interesting to make it pop-up at random location everytime Wink

So for random numbers: there is a command
code:
Rand.Int(parameter, parameter)


So i will go:
code:
win := Window.Open("graphics:"+Rand.Int(-50, 50)+","+Rand.Int(-50, 50))


But there is a problem since Rand.Int returns an int value, we cant add the string with the int.

So to convert an int into a string, we use the following command.
code:
instr(:int)


So now we will replace:

code:
intstr(Rand.Int(-50, 50))


Now, you can change the -50, 50. This makes the parameter a random one from -50 to 50

Example: 30
Example: -2

Mess around with the windows to get some different sized random windows.
ViRuAl_InFeCtiON_vErsIonX




PostPosted: Sat Jul 09, 2005 11:50 am   Post subject: thanks

ok thanks i did read then posts about how process should be avoid and why they should and how they should only be really used for music. and i thibnk it was someone else said something to put it into smnaller loops or something put the point it is that i read it

Thanks for the help

Very Happy
MysticVegeta




PostPosted: Sat Jul 09, 2005 5:00 pm   Post subject: (No subject)

oh, with Turing 4.0.5, you dont need processes at all!!!! There is a Music.PlayFileLoop that can serve this purpose. With this command you can have turing run the program and the music simultaneously. Wink
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 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: