ItsDeltin / Overwatch-Script-To-Workshop

Converts scripts to Overwatch workshops.
208 stars 24 forks source link

Renaming a function will cause the function call statement lose argument part #296

Closed ghost closed 3 years ago

ghost commented 3 years ago

Version: OSTW2.0-beta.12

rename

test code:

Any Add(in define a,in define b){
    return a+b;
}

rule: 'My Rule'
{
    LogToInspector(Add(1, 2));
}

and another small question: should I use Any instead of define ?

ScreenShot_2021-02-17_04-59-34

Protowalker commented 3 years ago

and another small question: should I use Any instead of define ? It depends on what your use case is -- here, I would make the type of that Number or I would use a union type of Vector | Number. Usually I make a type alias to this called Operable:
type Operable = Number | Vector;

Operable Add(in Operable a, in Operable b): a + b;

though keep in mind that a could be a number and b could be a vector here, or vice-versa. That would cause issues and is only solvable with generics (which are on the way, but aren't ready yet).

ghost commented 3 years ago

and another small question: should I use Any instead of define ?

It depends on what your use case is -- here, I would make the type of that Number or I would use a union type of Vector | Number. Usually I make a type alias to this called Operable: type Operable = Number | Vector;

Operable Add(in Operable a, in Operable b): a + b;

though keep in mind that a could be a number and b could be a vector here, or vice-versa. That would cause issues and is only solvable with generics (which are on the way, but aren't ready yet).

Thank you very much for your detailed answer. First of all, I have to apologize for using misleading examples and for not describing my problem well.

I did read all the wiki pages to learn how to use OSTW, I remember when I followed the example in wiki to declare a global variable, I see the dotted line under define and when I hover over it, it says "Unable to infer type" . Since I only have a very basic knowledge of C++, I don't really understand what define does, or is it deprecated now?

But nvm, this is really just a random question. I've been using OSTW for a week now and have made a few little things with it. OSTW is really a great project and I really appreciate all the effort you guys put into it.

Protowalker commented 3 years ago

Quick correction -- OSTW is based quite a bit on C#, not C++.
define attempts to figure out the type of your variable based on context. If it can't figure it out, it gives you that warning and defaults to the Any type. When it says it can't infer the type, you should give it the type manually.

ghost commented 3 years ago

Quick correction -- OSTW is based quite a bit on C#, not C++. define attempts to figure out the type of your variable based on context. If it can't figure it out, it gives you that warning and defaults to the Any type. When it says it can't infer the type, you should give it the type manually.

Thank you for your patience and explanation, I now understand what define is used for.

Well, to learn OSTW I read the code of the Lava project a few days ago (I was interested in the host menu part) and this dotted line is everywhere even in Lava, which confused me at the time ( In order not to see these dotted lines I just replaced all define with Any, which is really embarrassing now that I think about it. 🤦‍♂️)

btw, I understand that OSTW is based on C#, but my English is really a mess, in fact I meant to say that I have just a little knowledge of C++ (but know nothing about C#). Sorry for the miscommunication caused by this.

Thanks for help me understand these, Have a nice day.

Protowalker commented 3 years ago

Well, to learn OSTW I read the code of the Lava project a few days ago (I was interested in the host menu part) and this dotted line is everywhere even in Lava, which confused me at the time ( In order not to see these dotted lines I just replaced all define with Any, which is really embarrassing now that I think about it. man_facepalming)

Yeah, the Lava project is a bit outdated (2.0 includes a lot of major changes to OSTW). Thanks for the reminder to update it!

btw, I understand that OSTW is based on C#, but my English is really a mess, in fact I meant to say that I have just a little knowledge of C++ (but know nothing about C#). Sorry for the miscommunication caused by this.

No problem! I just wanted to clarify so you wouldn't get confused when something in OSTW was significantly different than C++.

Thanks for help me understand these, Have a nice day.

You're welcome! You too :)

ItsDeltin commented 3 years ago

Fixed in v2.0