generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Help with C#

Previous Thread :: Next Thread 
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
26 Dec 2011 09:38 PM
As some of you know, today is my first day learning C#

I need to know how to make a void withing a void

Like say, I have a function

private void InitializeComponent()
{

}


How would I put another function/void inside of it, like:

private void InitializeComponent()
{
private void Function2()
{
};
}
Report Abuse
LocalChum is not online. LocalChum
Joined: 04 Mar 2011
Total Posts: 6906
26 Dec 2011 09:40 PM
You can't. All functions must be within the class declaration.
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
26 Dec 2011 09:42 PM
D:

Now my thing is gonna be thousands of lines long :V
Report Abuse
1Ra is not online. 1Ra
Joined: 02 May 2010
Total Posts: 2400
26 Dec 2011 09:44 PM
Now THAT is what she said ​>:P
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
26 Dec 2011 09:45 PM
1Ra, go back to farting blood.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
26 Dec 2011 09:46 PM
If it needs to be 1000 lines long then you're doing it wrong. Explain what you want to do.
Report Abuse
1Ra is not online. 1Ra
Joined: 02 May 2010
Total Posts: 2400
26 Dec 2011 09:46 PM
My history is already written!

i have to go back to the future.
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
26 Dec 2011 09:49 PM
Can't you use lambdas to achieve something similar?
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
26 Dec 2011 09:49 PM
@xSTRAVANTx

This is what I want .... (ignore variables)

using System;
using System.Drawing;
using System.Windows.Forms;

public class frmMain : Form
{
#region Windows code
private void InitializeComponent()
{
private void Function2()
{
// Errors :'(
}
}
#endregion

public frmMain()
{
InitializeComponent();
}

public static void Main()
{
frmMain main = new frmMain();
Application.Run(main);
}
}
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
26 Dec 2011 09:54 PM
No help :c?
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
26 Dec 2011 09:56 PM
Why do you need it to be that way though. You don't do things that way in static languages like C#.
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
26 Dec 2011 09:57 PM
Well, can I access variables made in one private void in another?
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
26 Dec 2011 10:01 PM
You pass it as an argument to the function, yes.
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
26 Dec 2011 10:03 PM
Help? (might be latetoast)
Report Abuse
pokelover980 is not online. pokelover980
Joined: 12 Jun 2009
Total Posts: 4141
26 Dec 2011 10:05 PM
"Well, can I access variables made in one private void in another?"

Pass by reference if you want to modify the values inside the other function without having to return anything. Example:

private void SomeFunc(ref int firstVar, ref int secondVar, ref int thirdVar)
{
firstVar = secondVar + thirdVar;
secondVar = firstVar - thidVar;
thirdVar += firstVar * secondVar;
}

This modifies each variable, and when you return to your main function the variables will remain modified. However, this way seems less neat if you're passing multiple values but only need to return one value, in which case you're better off doing something like:

int SomeVar = 5;
SomeVar += SomeOtherFunction(3, 6);

...

private int SomeOtherFunction(int FirstVar, int SecondVar)
{
return FirstVar + SecondVar;
}
Report Abuse
pokelover980 is not online. pokelover980
Joined: 12 Jun 2009
Total Posts: 4141
26 Dec 2011 10:06 PM
And I forgot to say you can use that to build off of if you need to return nothing at all, and you just need the values of the variables.
Report Abuse
NVI is not online. NVI
Joined: 11 Jan 2009
Total Posts: 4744
27 Dec 2011 12:29 AM
"Well, can I access variables made in one private void in another?"

Make them member variables of the class. Welcome to OOP.
Report Abuse
themasterofalllegos is not online. themasterofalllegos
Joined: 21 Aug 2010
Total Posts: 39
28 Mar 2013 02:09 PM
I don't know if you resolved this but here.

public static int a = 1; //THIS IS A GLOBAL VARIABLE SO ALL FUNCTIONS CAN USE IT
public static void main(String[] args)
{
}

public static void second()
{
a = 2;//CALLS THE GLOBAL VARIABLE AND CHANGES IT
}
Report Abuse
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
28 Mar 2013 02:10 PM
^
hi u ok
Report Abuse
BAUER102 is online. BAUER102
Joined: 03 Apr 2010
Total Posts: 5936
28 Mar 2013 02:17 PM
wow you're pretty early
Report Abuse
Fattycat17 is not online. Fattycat17
Joined: 26 Jun 2011
Total Posts: 1527
28 Mar 2013 02:19 PM
Lol that was a large bump...
Report Abuse
awsumpwner27 is not online. awsumpwner27
Joined: 03 Sep 2011
Total Posts: 4389
28 Mar 2013 02:21 PM
The people you're helping are essentially an internet form of dead.

Dead people are:
-Not likely to move
-Not likely to speak
-Not likely to ever be alive again

The dead are past help.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image