✅ Method calling help

What are ways I can call a void method in start()?
No description
151 Replies
Pobiega
Pobiega14mo ago
Just call the method. Literally.
ShiftGamer2004
ShiftGamer2004OP14mo ago
like, what do I type exactly?
Pobiega
Pobiega14mo ago
This is one of the very first things you'd learn in C#
ShiftGamer2004
ShiftGamer2004OP14mo ago
im looking through notes i forgot
Pobiega
Pobiega14mo ago
Google it You'll need to put in some bare minimum effort before we help, honestly.
ShiftGamer2004
ShiftGamer2004OP14mo ago
would it be I do smt like "Debug.Log(SayHelloThrice);"?1
Pobiega
Pobiega14mo ago
try it
ShiftGamer2004
ShiftGamer2004OP14mo ago
or am i thinking too much
Pobiega
Pobiega14mo ago
$tias
ShiftGamer2004
ShiftGamer2004OP14mo ago
ok OH WAIT
Angius
Angius14mo ago
From what you said so far... you know how to call a method
ShiftGamer2004
ShiftGamer2004OP14mo ago
am i going in the right direction?
No description
ShiftGamer2004
ShiftGamer2004OP14mo ago
i can kinda see a problem
Pobiega
Pobiega14mo ago
somewhat
ShiftGamer2004
ShiftGamer2004OP14mo ago
that like the start() thing isnt able to reach the method outside of it
Angius
Angius14mo ago
Uh, no It is able to reach the method Read the error message
ShiftGamer2004
ShiftGamer2004OP14mo ago
oooh cannot convert method group to object
Angius
Angius14mo ago
Yep
ShiftGamer2004
ShiftGamer2004OP14mo ago
so it CAN reach it, but its being used incorrectly
Pobiega
Pobiega14mo ago
yes
Angius
Angius14mo ago
Because Debug.Log() expects an object to be passed to it
ShiftGamer2004
ShiftGamer2004OP14mo ago
ah
Angius
Angius14mo ago
And you're giving it the method itself
ShiftGamer2004
ShiftGamer2004OP14mo ago
ok
Angius
Angius14mo ago
So, two issues: 1. You're not actually calling your method still 2. Even if you were, that method is void, it does not return any sort of an object
ShiftGamer2004
ShiftGamer2004OP14mo ago
oh yeah mb a method would be smt like "public class (method name)" right? minus the ()
Angius
Angius14mo ago
Uh, no
ShiftGamer2004
ShiftGamer2004OP14mo ago
oh
Angius
Angius14mo ago
public class Something declares a class Your method is defined
ShiftGamer2004
ShiftGamer2004OP14mo ago
true
Angius
Angius14mo ago
You just need to... call it Like you called the Debug.Log method
ShiftGamer2004
ShiftGamer2004OP14mo ago
ok, imma go through my notes rq yeah so void methods are as it says, voided right?
Pobiega
Pobiega14mo ago
uhm, what would that mean exactly?
ShiftGamer2004
ShiftGamer2004OP14mo ago
wait
Angius
Angius14mo ago
A method being void means it doesn't return anything
ShiftGamer2004
ShiftGamer2004OP14mo ago
ok so if i wanted this ti appear in the console, it wouldnt because its void
Pobiega
Pobiega14mo ago
your SayHelloThrice method already calls Debug.Log inside it you don't need to Debug.Log a Debug.Log
ShiftGamer2004
ShiftGamer2004OP14mo ago
oooh
Pobiega
Pobiega14mo ago
(and Debug.Log is also a void method)
ShiftGamer2004
ShiftGamer2004OP14mo ago
ok so if i can use Debug.Log to call a method, but I cant in this scenario
Pobiega
Pobiega14mo ago
no Debug.Log is not related at all to calling methods
ShiftGamer2004
ShiftGamer2004OP14mo ago
ok
Pobiega
Pobiega14mo ago
other than in that it is itself a method
ShiftGamer2004
ShiftGamer2004OP14mo ago
so im in the completely wrong area ok so i cant use debug.log, what should I use?
Pobiega
Pobiega14mo ago
how about the method you made? the one you want to call
ShiftGamer2004
ShiftGamer2004OP14mo ago
do i just put in start() "SayHelloThrice"? imma try it nope
Pobiega
Pobiega14mo ago
show us your attempt
ShiftGamer2004
ShiftGamer2004OP14mo ago
No description
Pobiega
Pobiega14mo ago
so close so very very close
ShiftGamer2004
ShiftGamer2004OP14mo ago
MMMM wait
Pobiega
Pobiega14mo ago
Look at all the methods you've made and used so far
ShiftGamer2004
ShiftGamer2004OP14mo ago
do i put void infront of it?
Pobiega
Pobiega14mo ago
what do they all have in common? no
ShiftGamer2004
ShiftGamer2004OP14mo ago
or behind it
Pobiega
Pobiega14mo ago
that would be a declaration
ShiftGamer2004
ShiftGamer2004OP14mo ago
true
Pobiega
Pobiega14mo ago
no, that would be invalid syntax remember, Debug.Log is a void method and you call it succesfully and correctly in your method
ShiftGamer2004
ShiftGamer2004OP14mo ago
hmmmmmmmmmmm im so close, yet im still missing a piece of the puzzle
Pobiega
Pobiega14mo ago
hint: its round or at least curved
ShiftGamer2004
ShiftGamer2004OP14mo ago
PARENTHESIS right?
Pobiega
Pobiega14mo ago
$tias
ShiftGamer2004
ShiftGamer2004OP14mo ago
I THINK IT WORK :D
No description
Angius
Angius14mo ago
🎉
ShiftGamer2004
ShiftGamer2004OP14mo ago
no red squiggle :D i feel accomplished, yet dumb
ShiftGamer2004
ShiftGamer2004OP14mo ago
ok now I need to figure out how to make it say hello 3 times in the console for context I used a for while in the method to i = 0;i<3:i++
Pobiega
Pobiega14mo ago
no, you used a for loop there is no while loop there
ShiftGamer2004
ShiftGamer2004OP14mo ago
well yeah a for loo[ loop mb i assume i would have to Debug.Log it so it appears in the console or like Debug.Log("Hello"); my question goes to where inside the call would i put it if i put it there at all no
Pobiega
Pobiega14mo ago
did you run the code you posted?
ShiftGamer2004
ShiftGamer2004OP14mo ago
yes nothing showed in console
MODiX
MODiX14mo ago
Pobiega
REPL Result: Success
for (int i = 0; i < 3; i++)
{
Console.WriteLine(i);
}
for (int i = 0; i < 3; i++)
{
Console.WriteLine(i);
}
Console Output
0
1
2
0
1
2
Compile: 410.497ms | Execution: 45.703ms | React with ❌ to remove this embed.
Pobiega
Pobiega14mo ago
(this is normal C#; not unity)
ShiftGamer2004
ShiftGamer2004OP14mo ago
im using unity
Pobiega
Pobiega14mo ago
I'm not. Deal with it.
ShiftGamer2004
ShiftGamer2004OP14mo ago
😭
Angius
Angius14mo ago
Unity will use Debug.Log() instead of Console.WriteLine()
ShiftGamer2004
ShiftGamer2004OP14mo ago
ok
Pobiega
Pobiega14mo ago
Console.WriteLine is more or less identical to Debug.Log yeah
ShiftGamer2004
ShiftGamer2004OP14mo ago
hm
Pobiega
Pobiega14mo ago
so tell me, how would you modify the above code so that instead of 0 1 2, it printed hello hello hello?
ShiftGamer2004
ShiftGamer2004OP14mo ago
switch statement?
Pobiega
Pobiega14mo ago
what O_O how... what.. wat
ShiftGamer2004
ShiftGamer2004OP14mo ago
no iforgot what it was its in my memory somewhere
Pobiega
Pobiega14mo ago
"What do I need to add to 1 to make 2?` the square root of i^e8
ShiftGamer2004
ShiftGamer2004OP14mo ago
😭
Pobiega
Pobiega14mo ago
a switch statement is a control flow thing
ShiftGamer2004
ShiftGamer2004OP14mo ago
true
Pobiega
Pobiega14mo ago
it allows you to branch your code
ShiftGamer2004
ShiftGamer2004OP14mo ago
hm
Pobiega
Pobiega14mo ago
you need no branching here you just need to replace the values 0 1 2 with "hello hello hello"
ShiftGamer2004
ShiftGamer2004OP14mo ago
whats the code to do that?
Pobiega
Pobiega14mo ago
no look
for (int i = 0; i < 3; i++)
{
Console.WriteLine(i);
}
for (int i = 0; i < 3; i++)
{
Console.WriteLine(i);
}
this is the code
ShiftGamer2004
ShiftGamer2004OP14mo ago
yes wait
Pobiega
Pobiega14mo ago
do you understand WHY it prints 0 1 2?
ShiftGamer2004
ShiftGamer2004OP14mo ago
do i literally just put (string "hello, hello, hello") or just hello with the string
Pobiega
Pobiega14mo ago
"with the string"?
ShiftGamer2004
ShiftGamer2004OP14mo ago
(string("hello")) (string "hello") i mean
Pobiega
Pobiega14mo ago
no why would you even think that where have you seen that syntax?
ShiftGamer2004
ShiftGamer2004OP14mo ago
anyways i would think it prints out it because of i
Pobiega
Pobiega14mo ago
right.
ShiftGamer2004
ShiftGamer2004OP14mo ago
and because teh code calls for it to be 0, 1, 2 not calss what is it anyways
Pobiega
Pobiega14mo ago
... declares? increments?
ShiftGamer2004
ShiftGamer2004OP14mo ago
yeah one of those words
Pobiega
Pobiega14mo ago
its a loop. it runs while i is less than 3
ShiftGamer2004
ShiftGamer2004OP14mo ago
yes
Pobiega
Pobiega14mo ago
and at the end of each iteration, it increments i thats what that code does, indeed so how do we modify this to instead of the current i value, print "hello"?
ShiftGamer2004
ShiftGamer2004OP14mo ago
hm
Pobiega
Pobiega14mo ago
don't overthink it its much simpler than you assume
ShiftGamer2004
ShiftGamer2004OP14mo ago
its hard for me :( wait is it smt like 0 = hello
Pobiega
Pobiega14mo ago
no, we need i to be 0 1 and 2 to control how many times we print
ShiftGamer2004
ShiftGamer2004OP14mo ago
ok
Pobiega
Pobiega14mo ago
but there is no reason the body of the loop must use i
ShiftGamer2004
ShiftGamer2004OP14mo ago
hm
Pobiega
Pobiega14mo ago
I'm not gonna spoonfeed you this one. Figure it out.
ShiftGamer2004
ShiftGamer2004OP14mo ago
cant use string
Pobiega
Pobiega14mo ago
overthinking it go simpler
ShiftGamer2004
ShiftGamer2004OP14mo ago
hm
Pobiega
Pobiega14mo ago
you need to write a grand total of 7 characters.
ShiftGamer2004
ShiftGamer2004OP14mo ago
including spaces? wait
Pobiega
Pobiega14mo ago
grand total
ShiftGamer2004
ShiftGamer2004OP14mo ago
yeah
Pobiega
Pobiega14mo ago
including everything hint: how many characters is in the word hello?
ShiftGamer2004
ShiftGamer2004OP14mo ago
5
Pobiega
Pobiega14mo ago
so that leaves you with how many to spare?
ShiftGamer2004
ShiftGamer2004OP14mo ago
2
Pobiega
Pobiega14mo ago
mhm
ShiftGamer2004
ShiftGamer2004OP14mo ago
(something here) = hello
Pobiega
Pobiega14mo ago
nope, you're out of characters
ShiftGamer2004
ShiftGamer2004OP14mo ago
shit
Pobiega
Pobiega14mo ago
= hello is 7
ShiftGamer2004
ShiftGamer2004OP14mo ago
"hello" ?
Pobiega
Pobiega14mo ago
there you go I want 25 minutes of my life back 🙂 so, again
for (int i = 0; i < 3; i++)
{
Console.WriteLine(i);
}
for (int i = 0; i < 3; i++)
{
Console.WriteLine(i);
}
how do we modify this?
ShiftGamer2004
ShiftGamer2004OP14mo ago
i already tried switching out i for "hello", didnt work crosses taht out
Pobiega
Pobiega14mo ago
you sure?
MODiX
MODiX14mo ago
Pobiega
REPL Result: Success
for (int i = 0; i < 3; i++)
{
Console.WriteLine("hello");
}
for (int i = 0; i < 3; i++)
{
Console.WriteLine("hello");
}
Console Output
hello
hello
hello
hello
hello
hello
Compile: 438.363ms | Execution: 64.400ms | React with ❌ to remove this embed.
Pobiega
Pobiega14mo ago
works pretty well for me.
ShiftGamer2004
ShiftGamer2004OP14mo ago
thats weird it didnt work for me
Pobiega
Pobiega14mo ago
Might I suggest you leave unity? Its not really helping you at all
ShiftGamer2004
ShiftGamer2004OP14mo ago
cant school homework
Pobiega
Pobiega14mo ago
its a really powerful game engine, but you're literally trying to take your very first steps in programming its like giving a toddler a monstertruck before they can walk
ShiftGamer2004
ShiftGamer2004OP14mo ago
tell that to my teacher half the class dont know how to do shit me included
Pobiega
Pobiega14mo ago
thasts because you shouldn't start with unity, and either your teacher absolutely sucks at explaining the basics, or you were all sleeping $helloworld
Pobiega
Pobiega14mo ago
go through the interactive course here, and you'll learn the basics of C# that will all apply to unity too
ShiftGamer2004
ShiftGamer2004OP14mo ago
ok
Pobiega
Pobiega14mo ago
how to decalre a method, how to call it, how to use variables, literals, etc all that is covered
ShiftGamer2004
ShiftGamer2004OP14mo ago
i think im just gonna turn this assignment in because its 15 minutes till its due im gonna take a hit rq thanks for the help you provided so far ill learn it better eventually enjoy the rest of your day
Pobiega
Pobiega14mo ago
$close
MODiX
MODiX14mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server