|
Post by MonstaWolf on Feb 26, 2016 13:14:47 GMT
Hai, I'm trying to edit this snippet of script so that it randomly picks an object to show. When it launches, it doesn't just show one, but shows them all at once, which is not how I need it to function. I've double checked everything; they all start out hidden, and I have an extra script to hide them when needed. If I simply set (j) to 0, it shows the first car on the list, as it should. I get no errors, so I have all of the variables and stuff correct, no need to correct that. Have I found a glitch in AngelScript, or did I mistype something?
The script:
vehicle[0]= (OBJ_22); vehicle[1]= (OBJ_242); vehicle[2]= (OBJ_264); vehicle[3]= (OBJ_286); vehicle[4]= (OBJ_308); vehicle[5]= (OBJ_330); vehicle[6]= (OBJ_352); //string[] wso= {"0.65", "0.65", "0.6", "0.6", "0.65", "0.57", "0.66",}; //string[] fwfo= {"2.29", "2.40", "2.11", "2.235", "2.27", "2.29", "2.29",}; //string[] rwfo= {"-0.28", "-0.24", "-0.16", "-0.035" "-0.4", "-0.6", "-0.25",}; Ignore these three for now, I'm going to put them into proper action once I get this working. And I know I need to change them to integers, I'm just too lazy for now XP
int j= iFloatRand(0,7); carSkin= vehicle[j];
iObjectShow(vehicle[j]);
|
|
|
Post by Power Supersport on Feb 26, 2016 13:59:20 GMT
It's all at once, because your script is cycling 60 times per second... And the randomized number is 60 times changed... And it practically selects every value... You can fix this by using: int time; void Main() {
if (time < 3) time += 1; if (time == 1) { int j= iFloatRand(0,7); carSkin= vehicle[j]; iObjectShow(vehicle[j]); } } You can set up the script by your taste... It's just the shortest way to show it to you... I am sure it will work... So, I hope it helped you...
|
|
|
Post by MonstaWolf on Feb 26, 2016 14:57:07 GMT
I can see where you're going with this, but I tried putting it in the script, and now it just shows none of the skinmeshes :/
|
|
|
Post by Power Supersport on Feb 26, 2016 17:19:03 GMT
So what's your purpose to do with this script? Tell me what do you need...
|
|
|
Post by TinSoldier on Feb 28, 2016 21:36:00 GMT
The first issue i see is that your not hiding the other objects. the small sample script is "showing" each as selected by the random number, but i assume you only want one of them to be visable at any given time, so you have to hide the others each time a new one is selected. If you dont hide them it could seem like the random number process isnt working. only issue i can see, plus if you dont have a trigger or timer as well 3drad will generate all the random numbers in a couple seconds and show all the objects. if this still isnt working, you'll need to share more of the script... Hai, I'm trying to edit this snippet of script so that it randomly picks an object to show. When it launches, it doesn't just show one, but shows them all at once, which is not how I need it to function. I've double checked everything; they all start out hidden, and I have an extra script to hide them when needed. If I simply set (j) to 0, it shows the first car on the list, as it should. I get no errors, so I have all of the variables and stuff correct, no need to correct that. Have I found a glitch in AngelScript, or did I mistype something? The script: vehicle[0]= (OBJ_22); vehicle[1]= (OBJ_242); vehicle[2]= (OBJ_264); vehicle[3]= (OBJ_286); vehicle[4]= (OBJ_308); vehicle[5]= (OBJ_330); vehicle[6]= (OBJ_352); //string[] wso= {"0.65", "0.65", "0.6", "0.6", "0.65", "0.57", "0.66",}; //string[] fwfo= {"2.29", "2.40", "2.11", "2.235", "2.27", "2.29", "2.29",}; //string[] rwfo= {"-0.28", "-0.24", "-0.16", "-0.035" "-0.4", "-0.6", "-0.25",}; Ignore these three for now, I'm going to put them into proper action once I get this working. And I know I need to change them to integers, I'm just too lazy for now XP int j= iFloatRand(0,7); carSkin= vehicle[j]; iObjectShow(vehicle[j]);
|
|
|
Post by MonstaWolf on Feb 29, 2016 13:30:21 GMT
I am hiding the other objects in another script. This is just a small snippet. I will try what you said, wish me luck
|
|
|
Post by NicusorN5 on Jun 16, 2016 14:13:51 GMT
The other script , that hides the skinmeshes , it uses iScriptStop() ?
|
|
|
Post by TinSoldier on Jun 17, 2016 7:20:53 GMT
i also just noticed, 0 to 7 is wrong, you only use 0 to 6...
This may cause an error when random number #7 is selected to display and there is no model #7 to display..
This would be an "array out of range" type error.
|
|
|
Post by Power Supersport on Jun 17, 2016 7:42:00 GMT
Just to clarify, iFloatRand really doesn't choose the last value... If you are between range (0, 7) it will choose between 0 - 6 inclusive, without the 7...
|
|
|
Post by TinSoldier on Jun 17, 2016 22:50:31 GMT
Ok i didnt test it but did consider that... buttttt Are you suggesting 3drad is actually doing something smart ? .. I say this because if 3drad isn't selecting number 7 but is selecting number 0, how does it decide not to select the the upper number but does select the lower number ... If the range was 4 to 8 will it select 4 to 7 or 5 to 7 ... the more i think of it without testing it.. i cant decide if this is smart or stupid Now i'm going to have to test this just so i know for myself if 3drad is being smart or stoopid with this random number equation... Damn you @power Supersport , i'm blaming you for this!
|
|
|
Post by F1Andre on Jun 17, 2016 23:52:32 GMT
Haha TinSoldier , hope you come back to us with an answer. It's actually quite interesting, but usually with these random number generators they exclude the max value you provide. Think of it like this, you are telling the computer to seek a random number from 4 to 7 (4 >= x < 7). That means you exclude the number 7 and since you want a integer, it will spew out a six.
|
|
|
Post by Power Supersport on Jun 18, 2016 8:03:34 GMT
I have the experience that even Unity doesn't... They all chose the values without the last... I don't know what's the reason for this... But if you're using Range (0,1) it will choose 0 or 1... But if you do (0,2) it will again chose between 0 and 1... Very interesting stuff, but that's what I witnessed in 3D Rad and Unity...
|
|
|
Post by TinSoldier on Jun 18, 2016 19:35:49 GMT
Ok so i threw this script together that tests for both the upper and lower random values being selected and counts 1 for each hit. I figured 2000 tests for each ( 0 or 7 ) and ( 1 or 8 ) test should be good enough. Problem is i'm getting inconclusive results and have had negative returned hit values.. It appears my script is crashing and producing erroneous results but not producing an error message.. ( error message reporting happens to be one of 3drads known bugs ! ) Here's the program ready to run dl.dropbox.com/s/dcqd0rqw8z2pcw6/Random_Float_Test.3dr?dl=1or here's the script i came up with. Do you see an error i missed or something wrong, i don't... int[] Cnt(4); int Tin=0; int Tin2=0;
float RandomNumber=0.0f; float RandomNumber2=0.0f;
void Main(){
RandomNumber=0.0f;
for(Tin=1;Tin<2000;Tin++){
RandomNumber=iFloatRand(0.0f,8.0f); if(RandomNumber == 0.0f)Cnt[0]++; if(RandomNumber == 8.0f)Cnt[1]++; }
RandomNumber2=0.0f;
for(Tin2=1;Tin2<2000;Tin2++){
RandomNumber2=iFloatRand(1.0f,8.0); if(RandomNumber2 == 1.0f)Cnt[2]++; if(RandomNumber2 == 8.0f)Cnt[3]++; }
iPrint(Tin +" (0 and 8) tests done",-7.0f,4.0f,OBJ_0); iPrint("# of 0.0f hits "+Cnt[0]+"\r # of 8.0f hits "+Cnt[1],-7.0f,3.0f,OBJ_0);
iPrint(Tin2 +" (1 and 8) tests done",-7.0f,-2.0f,OBJ_0); iPrint("# of 1.0f hits "+Cnt[2]+"\r # of 8.0f hits "+Cnt[3],-7.0f,-3.0f,OBJ_0); }
|
|
|
Post by Power Supersport on Jun 18, 2016 20:28:43 GMT
After a lot of playing arround I think that I got it working... Attachments:Random_Float_Test.3dr (88.16 KB)
|
|
|
Post by TinSoldier on Jun 18, 2016 22:15:34 GMT
Ya thanks for that power, it is working and confirms the last number issue
So now i would call this an error, probably some math DLL commonly used in C programs and never been fixed or reported as an issue to the author ...
I would totally expect a random number of 0 to 8 to include both 0 and 8 or neither ....
|
|
|
Post by cypermethrin on Jun 18, 2016 22:32:50 GMT
C does something similar but fully documented - floats are inclusive, integers are exclusive - I'm guessing the angelscript function uses integers for each order of magnitude, ie for 0.0f it would get a int[0-8].int[0-9]
As bugs go its a pretty easy work around
|
|
|
Post by TinSoldier on Jun 18, 2016 22:35:06 GMT
PS if anyone didn't notice, i think the issue was probably just the
int[] Cnt(4);
I found this out a couple years back myself and confirmed it with Jestermon when i had a script with very weird results.
When ever an array is created in your script, it's a good idea, maybe required, too set default values to 0 just to prevent erroneous results, this is what Power did and what i totally forgot about.
I haven't checked / edited my own script to do this just to validate that as the only problem... but at first look i think it is the fault.
I blame 3drad for this basic error, you would think 3drad should clear or zero all array pieces during creation but it doesn't, quite possibly this may be the source of other errors that 3drad has that seem to popup randomly for no apparent reason..
I'm sure 3drad uses a ton of array's internally.. this could be fixed but who can say how much time it would take.
|
|