Closed ghost closed 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 ofVector | 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).
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 ofVector | 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.
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.
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 theAny
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.
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 :)
Fixed in v2.0
Version: OSTW2.0-beta.12
test code:
and another small question: should I use
Any
instead ofdefine
?