cpp-sdk icon indicating copy to clipboard operation
cpp-sdk copied to clipboard

`Expected` in ICore create methods

Open xxshady opened this issue 1 year ago • 0 comments

Currently SDK returns nullptr if it fails to create some base object, in some cases not even printing reason of it to console.

Suggestion

Make use of Expected in ICore base objects create methods, so modules implementing alt:V API can provide more info right in code to server developers.

Rust API example (Rust's Result<Ok, Err> is very similar to Expected type in SDK)

let result = altv::VoiceChannel::new(...);
match (result) {
  Ok(channel) => {
    // ...
  }
  Err(altv::VoiceChannelCreationError::VoiceChatIsNotEnabled) => {
    // ...
  }
}

SDK example

auto expected = alt::ICore::Instance().CreateVoiceChannel(...);

if(expected.success) {
    // using expected.value
} else {
  switch(expected.error) {
    case alt::VoiceChannelCreationError::VoiceChatIsNotEnabled:
      // ...
      break;
  }
}

xxshady avatar Jan 18 '24 19:01 xxshady