pass a variable over to another class

Asked 2 months ago, Updated 2 months ago, 0 views

I'm making a game.

·If you save 100 exps, you will be able to improve your level
·When you raise the level, you increase the variable value of the class called status class by one

There may be some parts that don't make sense here and there.

The problem is that if you pass the value of subclass (exp10) to mainclass and exp becomes 100 in mainclass,
I would like to level up and hand over the number 1 to another class (exampleclass).Also, please point out other wrong parts

Example: Defeat an enemy, get exp (10 exp)

class main {
public int expamount
public int exp
public void exp(){

main exp = new main();

exp.expamount

Level up if(exp>0); boolean(exp==100) true;//exp equals 100

return;



class sub{

enemy.cs void Main(){
public intget;


monster
if(monsterHP<0);get.exp(10);// If the monster's HP is 0, it gets the experience value of 10 exp.


}

c#

2022-09-30 11:38

1 Answers

I will use the answer field to point out the problem with the code in the questionnaire.

Do you mean that you are asking how to add public void main(int exp) and arguments to main()?

class main
{
    public int expamount;// Add semicolon
    public int exp;// Add semicolon

    Public void exp()// Is one of the fields an argument because the following is a "10"?
    {

        main exp = new main();

        exp.expamount;// Add semicolon

        // Do you mean experience value = previous experience value + acquisition experience value?
        // exp and expand

        Level up if(exp>0); boolean(exp==100) true;//exp equals 100
        /* ↑ statement doesn't make sense as C#

        if (experience > 0 & & experience == 100)
        {
            // true level-up process
        }

        Is this the intention?
        (I think inequality is better than ==100)but)

        */

        return;

    } // Add closed bracket
}  // Add closed bracket

class sub
{

    /* enemy.cs ← File name?*/
    void Main()
    {
        /* No public← attached */
        int get;
        // ↑get is the main type because it calls exp?

        monster;// ← What variable?
        If(monsterHP</*<=?*/0)//;You probably don't need a semicolon here.
            get.exp(10); // Get experience value of 10 exp when monster HP is 0.

    }
} // Add closed bracket


2022-09-30 11:38

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.