✅ Method calling help

What are ways I can call a void method in start()?
No description
151 Replies
Pobiega
Pobiega9mo ago
Just call the method. Literally.
ShiftGamer2004
ShiftGamer20049mo ago
like, what do I type exactly?
Pobiega
Pobiega9mo ago
This is one of the very first things you'd learn in C#
ShiftGamer2004
ShiftGamer20049mo ago
im looking through notes i forgot
Pobiega
Pobiega9mo ago
Google it You'll need to put in some bare minimum effort before we help, honestly.
ShiftGamer2004
ShiftGamer20049mo ago
would it be I do smt like "Debug.Log(SayHelloThrice);"?1
Pobiega
Pobiega9mo ago
try it
ShiftGamer2004
ShiftGamer20049mo ago
or am i thinking too much
Pobiega
Pobiega9mo ago
$tias
ShiftGamer2004
ShiftGamer20049mo ago
ok OH WAIT
Angius
Angius9mo ago
From what you said so far... you know how to call a method
ShiftGamer2004
ShiftGamer20049mo ago
am i going in the right direction?
No description
ShiftGamer2004
ShiftGamer20049mo ago
i can kinda see a problem
Pobiega
Pobiega9mo ago
somewhat
ShiftGamer2004
ShiftGamer20049mo ago
that like the start() thing isnt able to reach the method outside of it
Angius
Angius9mo ago
Uh, no It is able to reach the method Read the error message
ShiftGamer2004
ShiftGamer20049mo ago
oooh cannot convert method group to object
Angius
Angius9mo ago
Yep
ShiftGamer2004
ShiftGamer20049mo ago
so it CAN reach it, but its being used incorrectly
Pobiega
Pobiega9mo ago
yes
Angius
Angius9mo ago
Because Debug.Log() expects an object to be passed to it
ShiftGamer2004
ShiftGamer20049mo ago
ah
Angius
Angius9mo ago
And you're giving it the method itself
ShiftGamer2004
ShiftGamer20049mo ago
ok
Angius
Angius9mo 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
ShiftGamer20049mo ago
oh yeah mb a method would be smt like "public class (method name)" right? minus the ()
Angius
Angius9mo ago
Uh, no
ShiftGamer2004
ShiftGamer20049mo ago
oh
Angius
Angius9mo ago
public class Something declares a class Your method is defined
ShiftGamer2004
ShiftGamer20049mo ago
true
Angius
Angius9mo ago
You just need to... call it Like you called the Debug.Log method
ShiftGamer2004
ShiftGamer20049mo ago
ok, imma go through my notes rq yeah so void methods are as it says, voided right?
Pobiega
Pobiega9mo ago
uhm, what would that mean exactly?
ShiftGamer2004
ShiftGamer20049mo ago
wait
Angius
Angius9mo ago
A method being void means it doesn't return anything
ShiftGamer2004
ShiftGamer20049mo ago
ok so if i wanted this ti appear in the console, it wouldnt because its void
Pobiega
Pobiega9mo ago
your SayHelloThrice method already calls Debug.Log inside it you don't need to Debug.Log a Debug.Log
ShiftGamer2004
ShiftGamer20049mo ago
oooh
Pobiega
Pobiega9mo ago
(and Debug.Log is also a void method)
ShiftGamer2004
ShiftGamer20049mo ago
ok so if i can use Debug.Log to call a method, but I cant in this scenario
Pobiega
Pobiega9mo ago
no Debug.Log is not related at all to calling methods
ShiftGamer2004
ShiftGamer20049mo ago
ok
Pobiega
Pobiega9mo ago
other than in that it is itself a method
ShiftGamer2004
ShiftGamer20049mo ago
so im in the completely wrong area ok so i cant use debug.log, what should I use?
Pobiega
Pobiega9mo ago
how about the method you made? the one you want to call
ShiftGamer2004
ShiftGamer20049mo ago
do i just put in start() "SayHelloThrice"? imma try it nope
Pobiega
Pobiega9mo ago
show us your attempt
ShiftGamer2004
ShiftGamer20049mo ago
No description
Pobiega
Pobiega9mo ago
so close so very very close
ShiftGamer2004
ShiftGamer20049mo ago
MMMM wait
Pobiega
Pobiega9mo ago
Look at all the methods you've made and used so far
ShiftGamer2004
ShiftGamer20049mo ago
do i put void infront of it?
Pobiega
Pobiega9mo ago
what do they all have in common? no
ShiftGamer2004
ShiftGamer20049mo ago
or behind it
Pobiega
Pobiega9mo ago
that would be a declaration
ShiftGamer2004
ShiftGamer20049mo ago
true
Pobiega
Pobiega9mo 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
ShiftGamer20049mo ago
hmmmmmmmmmmm im so close, yet im still missing a piece of the puzzle
Pobiega
Pobiega9mo ago
hint: its round or at least curved
ShiftGamer2004
ShiftGamer20049mo ago
PARENTHESIS right?
Pobiega
Pobiega9mo ago
$tias
ShiftGamer2004
ShiftGamer20049mo ago
I THINK IT WORK :D
No description
Angius
Angius9mo ago
🎉
ShiftGamer2004
ShiftGamer20049mo ago
no red squiggle :D i feel accomplished, yet dumb
ShiftGamer2004
ShiftGamer20049mo 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
Pobiega9mo ago
no, you used a for loop there is no while loop there
ShiftGamer2004
ShiftGamer20049mo 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
Pobiega9mo ago
did you run the code you posted?
ShiftGamer2004
ShiftGamer20049mo ago
yes nothing showed in console
MODiX
MODiX9mo 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
Pobiega9mo ago
(this is normal C#; not unity)
ShiftGamer2004
ShiftGamer20049mo ago
im using unity
Pobiega
Pobiega9mo ago
I'm not. Deal with it.
ShiftGamer2004
ShiftGamer20049mo ago
😭
Angius
Angius9mo ago
Unity will use Debug.Log() instead of Console.WriteLine()
ShiftGamer2004
ShiftGamer20049mo ago
ok
Pobiega
Pobiega9mo ago
Console.WriteLine is more or less identical to Debug.Log yeah
ShiftGamer2004
ShiftGamer20049mo ago
hm
Pobiega
Pobiega9mo ago
so tell me, how would you modify the above code so that instead of 0 1 2, it printed hello hello hello?
ShiftGamer2004
ShiftGamer20049mo ago
switch statement?
Pobiega
Pobiega9mo ago
what O_O how... what.. wat
ShiftGamer2004
ShiftGamer20049mo ago
no iforgot what it was its in my memory somewhere
Pobiega
Pobiega9mo ago
"What do I need to add to 1 to make 2?` the square root of i^e8
ShiftGamer2004
ShiftGamer20049mo ago
😭
Pobiega
Pobiega9mo ago
a switch statement is a control flow thing
ShiftGamer2004
ShiftGamer20049mo ago
true
Pobiega
Pobiega9mo ago
it allows you to branch your code
ShiftGamer2004
ShiftGamer20049mo ago
hm
Pobiega
Pobiega9mo ago
you need no branching here you just need to replace the values 0 1 2 with "hello hello hello"
ShiftGamer2004
ShiftGamer20049mo ago
whats the code to do that?
Pobiega
Pobiega9mo 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
ShiftGamer20049mo ago
yes wait
Pobiega
Pobiega9mo ago
do you understand WHY it prints 0 1 2?
ShiftGamer2004
ShiftGamer20049mo ago
do i literally just put (string "hello, hello, hello") or just hello with the string
Pobiega
Pobiega9mo ago
"with the string"?
ShiftGamer2004
ShiftGamer20049mo ago
(string("hello")) (string "hello") i mean
Pobiega
Pobiega9mo ago
no why would you even think that where have you seen that syntax?
ShiftGamer2004
ShiftGamer20049mo ago
anyways i would think it prints out it because of i
Pobiega
Pobiega9mo ago
right.
ShiftGamer2004
ShiftGamer20049mo ago
and because teh code calls for it to be 0, 1, 2 not calss what is it anyways
Pobiega
Pobiega9mo ago
... declares? increments?
ShiftGamer2004
ShiftGamer20049mo ago
yeah one of those words
Pobiega
Pobiega9mo ago
its a loop. it runs while i is less than 3
ShiftGamer2004
ShiftGamer20049mo ago
yes
Pobiega
Pobiega9mo 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
ShiftGamer20049mo ago
hm
Pobiega
Pobiega9mo ago
don't overthink it its much simpler than you assume
ShiftGamer2004
ShiftGamer20049mo ago
its hard for me :( wait is it smt like 0 = hello
Pobiega
Pobiega9mo ago
no, we need i to be 0 1 and 2 to control how many times we print
ShiftGamer2004
ShiftGamer20049mo ago
ok
Pobiega
Pobiega9mo ago
but there is no reason the body of the loop must use i
ShiftGamer2004
ShiftGamer20049mo ago
hm
Pobiega
Pobiega9mo ago
I'm not gonna spoonfeed you this one. Figure it out.
ShiftGamer2004
ShiftGamer20049mo ago
cant use string
Pobiega
Pobiega9mo ago
overthinking it go simpler
ShiftGamer2004
ShiftGamer20049mo ago
hm
Pobiega
Pobiega9mo ago
you need to write a grand total of 7 characters.
ShiftGamer2004
ShiftGamer20049mo ago
including spaces? wait
Pobiega
Pobiega9mo ago
grand total
ShiftGamer2004
ShiftGamer20049mo ago
yeah
Pobiega
Pobiega9mo ago
including everything hint: how many characters is in the word hello?
ShiftGamer2004
ShiftGamer20049mo ago
5
Pobiega
Pobiega9mo ago
so that leaves you with how many to spare?
ShiftGamer2004
ShiftGamer20049mo ago
2
Pobiega
Pobiega9mo ago
mhm
ShiftGamer2004
ShiftGamer20049mo ago
(something here) = hello
Pobiega
Pobiega9mo ago
nope, you're out of characters
ShiftGamer2004
ShiftGamer20049mo ago
shit
Pobiega
Pobiega9mo ago
= hello is 7
ShiftGamer2004
ShiftGamer20049mo ago
"hello" ?
Pobiega
Pobiega9mo 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
ShiftGamer20049mo ago
i already tried switching out i for "hello", didnt work crosses taht out
Pobiega
Pobiega9mo ago
you sure?
MODiX
MODiX9mo 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
Pobiega9mo ago
works pretty well for me.
ShiftGamer2004
ShiftGamer20049mo ago
thats weird it didnt work for me
Pobiega
Pobiega9mo ago
Might I suggest you leave unity? Its not really helping you at all
ShiftGamer2004
ShiftGamer20049mo ago
cant school homework
Pobiega
Pobiega9mo 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
ShiftGamer20049mo ago
tell that to my teacher half the class dont know how to do shit me included
Pobiega
Pobiega9mo 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
Pobiega9mo ago
go through the interactive course here, and you'll learn the basics of C# that will all apply to unity too
ShiftGamer2004
ShiftGamer20049mo ago
ok
Pobiega
Pobiega9mo ago
how to decalre a method, how to call it, how to use variables, literals, etc all that is covered
ShiftGamer2004
ShiftGamer20049mo 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
Pobiega9mo ago
$close
MODiX
MODiX9mo ago
Use the /close command to mark a forum thread as answered