Author Topic: .SetInt() format  (Read 5846 times)

BaronArron

  • Guest
.SetInt() format
« on: August 10, 2017, 03:35:40 AM »
Hello,

I'm developing a plugin which allows various different data types to be read from the target application and fed back into VoiceAttack. For float/double/bool it's straight forward to determine what the conversion proccess should be. But for SetInt(), it's not clear from the documentation the exact integer format that this function expects (and as the proxy object is dynamic, there's no clear API).

Does SetInt() take signed or unsigned int? What about long integers?

Clarification on this would be great.

Thanks!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: .SetInt() format
« Reply #1 on: August 10, 2017, 11:31:13 AM »
Admittedly I'm just a novice programmer, but the documentation states "SetInt(string VariableName, int? Value) – Set a nullable integer value".

Look up the built-in C# datatypes and you'll find that translates to a signed int32, which in C# is referred to as "int". In VB.Net it would be an "Integer".
The questionmark signifies that it's nullable, so your code should be equipped to handle NULL values, if you're getting data from VoiceAttack.



and as the proxy object is dynamic, there's no clear API
If you mean there is no code completion because of this, that's a fair point, but the compiler will still tell you which values the function doesn't accept, E.G.:
Code: [Select]
public class VAInline
{
public void main()
{
            long test = 1;
VA.SetInt("myInt", test);
}
}
Quote
Compile errors: 2
7: The best overloaded method match for 'VoiceAttack.VoiceAttackInitProxyClass.SetInt(string, int?)' has some invalid arguments
7: Argument 2: cannot convert from 'long' to 'int?'

BaronArron

  • Guest
Re: .SetInt() format
« Reply #2 on: August 30, 2017, 04:50:15 AM »
Thanks for the reply.

I obviously overlooked the function signature in the docs which shows that SetInt() takes int :). That makes it clear what data type is required.

And regarding the proxy object: are you sure that the code you attached produces the output? The whole point of the dynamic keyword in C# is that the type isn't resolved until runtime, so the compiler has no idea what it is.

Admittedly I'm not a C# programmer and this plugin is the first time I've written any, so I'm not familiar with this construct. However, the same paradigm applies to most languages.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: .SetInt() format
« Reply #3 on: August 30, 2017, 10:37:06 AM »
regarding the proxy object: are you sure that the code you attached produces the output?
You'll note I used "VA" rather than "vaProxy", as I compiled from the "Inline Function - C# Code" editor.

Indeed, when running a plugin that attempts to pass an invalid datatype, you only get
Quote
Plugin initialization exception: The best overloaded method match for 'VoiceAttack.VoiceAttackInitProxyClass.SetInt(string, int?)' has some invalid arguments
Which sadly doesn't specify which arguments are invalid and why.