SRL Archive - SRL Suggestions

[Request] FindNormalRandoms2


bg5

2012-05-20 19:53:05

Ok ,so I found big problem ,when I wanted to add 'walk-back from failed random' to my script. FindNormalrandoms doesn't provide all needed information. It outputs TRUE ,if random was solved ,and FALSE ,when random failed either wasn't detected. So we don't know exactly where player is ,when something crash in script - it was failed random or our failed code? ;)

And if we have in script something like:

if not loggedin then LoginPlayer;
//or
AddOnTerminate('CrashSMART');
if not loggedin then terminatescript;

we don't know what to expect when we log in again - player might be: in script location , inside random or teleported somewhere for failed random. And it makes things overcomplicated. So I suggest

function FindNormalRandoms2 : integer // or byte
// output:
// -1 - failed random
// 0 - random not detected
// 1 - solved random

NCDS

2012-05-20 19:57:19

The main problem with this sort of implementation is that in many cases 'failed random' and 'random not detected' are one in the same.

bg5

2012-05-20 20:04:55

From: NCDS
The main problem with this sort of implementation is that in many cases 'failed random' and 'random not detected' are one in the same.


What do you mean? Randoms are detected or not ,and if detected then solver returns true or false.

NCDS

2012-05-20 20:13:02


So I suggest

function FindNormalRandoms2 : integer // or byte
// output:
// -1 - failed random
// 0 - random not detected
// 1 - solved random

0 and -1 could easily be mistaken for each other by the script, as if a random is present yet not detected, it is then 'failed', and there for the same thing.

bg5

2012-05-20 20:32:59

0 and -1 could easily be mistaken for each other by the script

I really don't understand this. I guess you maybe talk about a way ,how solver works:
 if (SRL_Randoms[rand].solve <> nil) and (SRL_Randoms[rand].solve())

,but I don't want to replace current FindNornalRandoms ,but add second expanded. Well ,maybe I should name it FindNormalRandomsEx.

There is not big deal to add it:


var
SRL_FailedRandomFlag : boolean; // global flag
function FindNormalRandomsEx : byte;
begin
SRL_FailedRandomFlag := FALSE; // reset flag
if FindNormalRandoms then
Result := 1
else begin
if SRL_FailedRandomFlag then Result := -1
else Result := 0;
end;
end;

then inside function _SolveRandom:

if (SRL_Randoms[rand].solve <> nil) and (SRL_Randoms[rand].solve()) then
begin
addToSRLLog('***** Solved Random: '+SRL_Randoms[rand].name+' *****');
players[currentPlayer].rand := '';
inc(SRL_Randoms[rand].solved);
solved := true;
end else
SRL_FailedRandomFlag := TRUE;

zmon

2012-05-20 20:37:37

From: NCDS
0 and -1 could easily be mistaken for each other by the script, as if a random is present yet not detected, it is then 'failed', and there for the same thing.


currently -1 and 0 option is being confused because they both return false, so that's a moot point

edit: i would prefer to have RANDOM_SOLVED, RANDOM_FAILED and RANDOM_NOT_FOUND defined of course….

NCDS

2012-05-20 21:14:15

I think I misunderstood what you posted..

If this is mainly meant to be a sort of debug, then I would much prefer just adding an attribute to the players array.

Something like:

//psuedo code..
if detectRandom then
begin
players[currentPlayer].inRandom := True;
if solveRandom then
players[currentPlayer].inRandom := False;
...

bg5

2012-05-20 21:36:38

I won't persist on my implementation ,there is few more ways. But how would you distinguish in your variant situation when random failed and player was teleported way? Statement:
(not FindNormalRandoms)and(not(players[currentPlayer].inRandom))
might mean:
no randoms detected
either
random failed and player was teleported away

Le Jingle

2012-05-20 21:44:03

Aren't you now both describing the same thing, or better yet, you both are identifying the same problem that occur, given each of your suggestions towards each other? If not, sorry, I'm just confused. :x

NCDS

2012-05-20 21:52:56

From: beginner5
I won't persist on my implementation ,there is few more ways. But how would you distinguish in your variant situation when random failed and player was teleported way? Statement:
(not FindNormalRandoms)and(not(players[currentPlayer].inRandom))
might mean:
no randoms detected
either
random failed and player was teleported away


You can always track most things yourself already with…

srl_OnFindRandom // A global pointer in SRL.
And now that I check, there is already..

Rand: string; // * Current Random
In the TUser record.

Honestly, It's all quite possible already. I'm not trying to shoot down your ideas by any means, but rather trying to avoid 'bloat' in the include. :)

bg5

2012-05-20 22:18:46

Well , you are right ,it's possible now.

var
InRandom : boolean;

function OnRandomDetect : Boolean;
begin
InRandom := TRUE;
end;

SRL_Procs[SRL_OnFindRandom] := @OnRandomDetected ;

function FindNormalRandomsEx : byte;
begin
InRandomFlag := FALSE;
if FindNormalRandoms then
Result := 1
else begin
if InRandomFlag then
Result := -1
else Result := 0;
end;
end;

E: I like TUser.inRandom idea :)

E2 : I didn't find .rand resets in other cases then random is solved. So when random fails and teleports player out ,it will still show ,that player is in random. And on the next FindNormalRandoms call ,which doesn't detect anything it will still shows ,that player is in random ,didn't it ? Maybe add reset of .rand at beginning of _SolveRandom? Propably no one expected ,that script will be running after failed random:)

zmon

2012-05-20 22:42:55

From: NCDS
Honestly, It's all quite possible already.


thanks for the thorough answer, i didn't check enough of code yet to know about all these things, very helpful :)

NCDS

2012-05-20 23:23:09

From: beginner5

E2 : I didn't find .rand resets in other cases then random is solved. So when random fails and teleports player out ,it will still show ,that player is in random. And on the next FindNormalRandoms call ,which doesn't detect anything it will still shows ,that player is in random ,didn't it ? Maybe add reset of .rand at beginning of _SolveRandom?

I'm not positive of which randoms will telport you, but those solvers should reset .rand accordingly, otherwise they should to be edited to do so.

From: zmon
thanks for the thorough answer, i didn't check enough of code yet to know about all these things, very helpful :)

SRL is full of possibilities and features not many are aware of. :)