Jump to content

is there a similar method to update() in c# and not unity

hey guys, I'm looking for some sort of method like update() from unity but in c#, visual studio, as that would work with what i need to do. 

 

is there a method like this in c# ? 

 

thanks :) 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, M.Yurizaki said:

What's "update" supposed to do?

ahh sorry, it calls all the statements in the method every frame 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, M.Yurizaki said:

I don't think C# has something like that except for Forms.Update, where it redraws the form.

ahh, see i need to constantly check something until the condition is right then once the code is executed i need it to start checking again, ive tried an infinite loop but it just keeps checking without finishing the code so it just spams the output in the console loads of times lol 

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, manlykeweaver465 said:

ahh, see i need to constantly check something until the condition is right then once the code is executed i need it to start checking again, ive tried an infinite loop but it just keeps checking without finishing the code so it just spams the output in the console loads of times lol 

You could create a custom event and have an event handler take care of it whenever the event fires off.

Link to comment
Share on other sites

Link to post
Share on other sites

Can you have the C# code set a flag for the once it executes?  Then, in a Do While Loop, check for the flag.   Note, it would be helpful if you provided more detail.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Most people use a while loop. 

 

Ie while (screen1.active ==true)

{

// do update

}

Link to comment
Share on other sites

Link to post
Share on other sites

I'm a little confused. There is an update method in C#, just do 

void Update(){

}

or for checking it 50 times per second, consistantly, which is less resource-intensive,

void FixedUpdate(){

}

But I'm guessing you mean in another language or something. message me back what your target language is.

Link to comment
Share on other sites

Link to post
Share on other sites

On 4/13/2018 at 4:14 PM, manlykeweaver465 said:

hey guys, I'm looking for some sort of method like update() from unity but in c#, visual studio, as that would work with what i need to do. 

C# has a very nice built in Publisher-Subscriber feature called "events". The model is a bit different than Unities Update model, but is much more powerful and useful.

From the first line in the introductory page on the matter:

Quote

Events enable a class or object to notify other classes or objects when something of interest occurs. The class that sends (or raises) the event is called the publisher and the classes that receive (or handle) the event are called subscribers.


In Unity, the Update method is called the publisher, and every method called inside of it is called a subscriber. This is exactly a Publisher-Subscriber pattern.

Here is the de-facto introduction to events:
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/events/

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×