question 1 - how to initialize array with default value question 2 - how to check weather there is value inside array or no value (garbage value) this is my program int[] IdArray(999); if(IdArray[Int_GetId]!=null) { IdArray[Int_GetId] = enemyLife; } it shows me error no conversion from int& to int available no conversion from const int' to 'int available then i tried int[] IdArray(999); if(IdArray[Int_GetId]!="") { IdArray[Int_GetId] = enemyLife; } it shows me error no conversion from 'string@&' to 'int available the solution i guessed to initialize the array element with -1 but how to do that without using for loop
Created on: 1 year ago
|
Hi, I rewrote your code snippet using a optional class type. class Optional { int Value; bool HasValue; Optional(int value) { Value = value; HasValue = true; } Optional() { Value = 0; HasValue = false; } } void Main() { int enemyLife = 200; int Int_GetId = 2; Optional[] IdArray(100); if(IdArray[Int_GetId].HasValue) { IdArray[Int_GetId].Value = enemyLife; } } I've never seen classes being used in 3D Rad previously, but this works. Further reading: https://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_class_desc.html Also, from your snippet, you don't seem to understand static typing. I recommend you learning a statically typed language like C, C#, C++, Rust, etc... You could also try reading https://en.wikipedia.org/wiki/Type_system
Created on: 1 year ago
|
Thanks NicusorN5 i will try and revert. There is another thing. I want to initialise 2 dimentional array with 10 x 10 elements. Is this possible in 3d rad I tried Int[][] idarray; this don't give error and also not executing. But Int[][] idarray(10)(10) give error....why How to initialise 2 dimension arrays
Created on: 1 year ago
Edited on: 1 year ago |
Created on: 1 year ago
|
I looked into it The array is initiased with variable I want to initialise at runtime. 3drad give error
Created on: 1 year ago
Edited on: 1 year ago |
in the 1st posts, you did not define 'enemyLife' as an int, therefore i assume it is a string or otherwise defined, if so you must convert the string to an int yourself
Created on: 1 year ago
|
class Optional { int Value; bool HasValue; Optional(int value) { Value = value; HasValue = true; } Optional() { Value = 0; HasValue = false; } } void Main() { int enemyLife = 200; int Int_GetId = 2; Optional[] IdArray(100); if(IdArray[Int_GetId].HasValue) { IdArray[Int_GetId].Value = enemyLife; } } the above code is giving error Optional[CURSER IS BLINKING HERE] IdArray(100); the error is - EXPECTED EXPRESSION VALUE
Created on: 10 months ago
|
Hi, I can't reproduce the compilation error inside 3D Rad. I've tried copying your snippet to a Script object, and "Check Script" doesn't report anything. I've used version 7.22.
Created on: 10 months ago
Edited on: 10 months ago |