Something simple I have wanted to (been struggling to) program for a little while?

Don’t really want a tweening engine like DOTween, they’re great, trying to learn though. Pretty novice here.

I can write a proper lerp with a start and end. I’m good there.

I can’t write a method that lerps any passed variable of a given type. Why? because I can’t pass an IEnumerator a reference (or pointer). I understand why this is. The coroutine is a lot bigger than what you write when you declare one. I understand I can put that variable in a container (a class) and pass that, or pass a delegate, or use a lambda(?) (I don’t understand lambda args)

Those methods all suck the fat one. I don’t want a class. I don’t want a data container. I want to tell a thing to alter a variable I pass it (not a copy, the original) over time, and I want to be able to throw that thing into any class and have it be functionally independent.

Any suggestions? Seems so brutally simple.

Sorry, but what?

If you have a variable in a class, lets just say a float for example and you want a coroutine to increment it, you can just have it run with a yield return waitforseconds and then increment in a loop. When you want to get the current value, you just access that variable. If it’s set to a global variable there are several ways to get it. You could use a method that just returns the value of that variable (thus calling it from another script if you want).

If for example you just want a method that you call, you pass in an int, it increments it and then returns the value, you can do that. But I think you need to explain a bit more about your use case because I’m not sure what you are really looking for.

we need an example code to give a more detailed answer, although sounds like you are looking for a function that returns some data, or using refs. The following have the trivial task of adding 1 to 0, but it is to show how they work more so than solve the issue:

//function with return type example

float a = 0f;

float AddOneTo(float value){
    return (value + 1f);
}

//usage
a = AddOneTo(a);//1 has been added to "a"
//refs example

float a = 0f;

void AddOneTo(ref float value){
    value += 1f;
}

//usage
AddOneTo(ref a);//1 has been added to "a"

If you don’t know the difference between pass by reference and pass by value don’t reply.

You don’t need more information or code if you’re actually a programmer. Everything I said has meaning to an actual programmer. Damn, it’s gotten impossible to talk about any of this (and damn hard to learn) with all these kids flooding every possible resource.

You can’t pass an IEnumerator block a reference, thus you can’t make a super-convenient lerp coroutine that lerps any parameter you pass it (without referencing that parameter inside the coroutine manually).

The only thing that was vague was that the lerp is happening over a series of frames, which is why I want an IEnumerator block to do it. Though, that should be assumed if you know what a lerp is since lerping in one frame would be pointless and a normal method can’t operate over many frames.

You could write a recursive function. That’s the only thing I can think to do but I don’t like calling a function every frame for the duration of a lerp. Is that an unfounded concern?

Then please present a script example of what you are facing. The problem here is not understanding what you are trying to achieve with what you are trying to do. So this will go one of two ways, either what you are trying to do can be done and someone knows, or an alternative way is found. I suspect you are overthinking your problem.

Sorry, I’m an actual programmer and I don’t quiet understand what you want to do. It seems you are looking for ways to implement tweening that would be both simple and easy to use (which is possible). What’s wrong with the existing packages or using coroutines?

1 Like

Not much of one if you can’t understand pass-by-reference vs pass-by-value.

Well see I mentioned the easy way in my OP, didn’t I?

What’s wrong with your reading comprehension? I mentioned I was trying to learn something, too.

Maybe you’re cool with mediocrity, I need deeper understanding than that. For the love of christ stop replying if you don’t even understand the premise of the OP, kids.

If you don’t know the difference between pass by reference and pass by value don’t reply.

Man, stop throwing a temper tantrum over here… You are really not helping yourself acting like that.

And…
http://bfy.tw/9A5R

First hit gives you 4 lovely examples

I do understand the difference.

I just don’t understand what you want do do or trying to learn. Try to clarify it to us. Maybe you could post some code piece of code of what you’ve already tried.

Your passive aggression is so much better than me expressing annoyance that people who can’t read and don’t understand basic computer programming terminology are replying to a generalized computer science question with demands for code samples.

I will accept this as an answer “No, there is not a way to do this without some kind of container.” since you were too rude to say it, and I have read and understand all of those examples.

Wow, are you kidding me. Just leave please.

Youre looking for help, a suggestions is a suggestion. We are ALL here to learn (as I think someone said In a different comment)

Just chill. You basically have your answer now.

What we dont understand is why you STILL havent shown us any code you have so far. Or even expanded on what it is exactly you want to do. For the love of f***ing god.

+1

Good, save us all the headache. All bow down to Master God Programmer perhaps one day we will all be as good as you.

The only reason you took the time to make that post was to personally attack me. It adds nothing to the conversation.

If you don’t understand a question about programming, consider the possibility that you don’t understand the concepts involved and consider studying them instead of replying.

Months ago I stopped posting here because it basically wasn’t possible to get useful information due to the number of spam posts. You’ll be glad to know I will not be coming back since the majority of the users in this forum need to go through a programming basics book, and maybe an English course to make them more comfortable reading written word and digesting it meaningfully.

What I wanted to do is possible in other programming contexts, but not possible in Unity’s implementation of C#.

I didn’t post code because it isn’t a question about code and I don’t need help writing code. It’s a question about pointers and coroutines.

PROTIP: if you want help, try being polite and civil.

7 Likes