SRL Archive - OSR Help

are booleans set false as default?


Sax

2012-11-22 17:58:32

When I use a boolean is it set False as default? Or is it True?
To set the boolean to False or True I do this

Boolean := True/False

But if I just use it without seting it? Is it False or True by default?

Sin

2012-11-22 17:59:18

I believe they retain a null statement, meaning neither true or false when initally called upon. (declaring it)

Chris

2012-11-22 18:03:14

program new;
var v: Boolean;
begin
if v then
writeln('v is true.')
else
writeln('v is false.');
end.

v is false.

Sax

2012-11-22 18:03:46

From: Shay
I believe they retain a null statement, meaning neither true or false when initally called upon. (declaring it)


so in the start of the procedure I have to set it to False so that if the procedure fails it returns false right?

Sax

2012-11-22 18:07:03

on a complete off-topic question. is there a procedure in includes to select options like this:


euphemism

2012-11-22 18:11:44

From: Nirvana
so in the start of the procedure I have to set it to False so that if the procedure fails it returns false right?


Booleans are false by default, integers are 0 by default, strings are empty by default.

Sax

2012-11-22 18:16:32

From: euphemism
Booleans are false by default, integers are 0 by default, strings are empty by default.


Thanks. What about the other non related question?

h4x_

2012-11-22 18:19:03

From: Nirvana
on a complete off-topic question. is there a procedure in includes to select options like this:



TypeSendEx('1', False); will select option 1
TypeSendEx('2', False); will select option 2

Sin

2012-11-22 18:29:25

Ah, that's interesting to know!

FindNPCChatText(); will do it.

Sax

2012-11-22 18:31:49

thanks.

masterBB

2012-11-22 18:35:29

A Boolean is simply an one or a zero. There is no null. Null is often used for object, like a TBitmap, where it is null because the object doesn't exist. Note that in some languages the memory space for a Boolean doesn't exist when you declare it, in that case you will have to set it. In simba you can set it to false at the start of you procedure or function, not for usefulness but for readability of the code.

Gu3st...

2012-11-22 18:38:49

Booleans are set to false on call, but there once was a bug in SRL which turned out to be an integer who did not reset after the procedure where the integer was declared internally didn't reset. Basically; in Pascal Script you can't be 100% sure it's always at False state upon declaration without setting it to false yourself, even though it should have been set to false.

riwu

2012-11-22 21:00:45

Zyt3x is right…
I've always thought that it's only for readability but in PS…

program new;
function TrueByDefault: Boolean;
begin
//Result:= False;
end;

begin
while not TrueByDefault do
wait(100);

writeln('We break out of an infinite loop! Time to switch to la-pe!');
end.

I got stuck for 15min today figuring out why a loop in my script ended prematurely…and i remembered this and sure enough, that bug is the cause of error.

Does that mean we should set other results (string, integer, arrays etc) to null/0 manually upon function entry as well?


EDIT: hmm could be a Simba bug actually… i ran it on a new Simba and it worked as expected, but on the original Simba…


Switching to la-pe (on the same bugged Simba) immediately fixed the problem.

Brandon

2012-11-22 21:17:08

What? Your code is named badly..

While Not FalseByDefault..


This will run infinitely because Not false is true..

A conditional statement/loop will run as long as the condition is true. This behaviour is perfectly normal. AFAIK, all languages set booleans to false by default.

Never heard of such a bug and I don't think such a bug would or did exist because by default, everything is set to off. You have to set it to >= 1 to turn it on. Computers read in binary. 1's and 0's. It will never start at one.

If such a bug did exist, someone programmed badly. I run your code and it works for me but my Simba is old.

riwu

2012-11-22 21:18:47

Yes, it should be false by default, but it ended up as true by default instead, as demonstrated in my screenshot above. (the loop breaks out and debug is shown)

I think it could be a Simba bug though, as opening a new Simba fixed the problem.

Gu3st...

2012-11-23 08:41:29

Simba has nothing to do with the code tbh; it is pascal script that is failing to address "new" variables correctly. The Interpreter is doing all the script work.

Moral of the story; Use la-pe or declare everything yourself.

Brandon

2012-11-23 08:43:05

From: Zyt3x
Simba has nothing to do with the code tbh; it is pascal script that is failing to address "new" variables correctly. The Interpreter is doing all the script work.

Moral of the story; Use la-pe or declare everything yourself.



Too buggy. Takes FOREVER to compile. XOR doesn't work 100% of the time. AddOnTerminate doesn't work.


var
BMP: Integer;

{$I SRL/SRL.Simba}

Procedure FreeBMP;
Begin
FreeBitmap(BMP);
End;

begin
Bmp := BitmapFromString(25, 23, 'meJxtlYtWm0AQhl+rrdZ7buQCJN' +
'Fa7StVE2C56jNYE5ZdEu2z9Z8dQDA95zs5hLP75Z+ZDej0p2aSO3z' +
'usw922U2ZXutkqeJFEc0ZGboycpgidlXk6Ngtk/k+W7KnzO6Yt6e7' +
'96cfb9nNPr3eJcsyXuhoTphdbXCHiOZYg5W0uJYAJPn7fMuqxqNCl' +
'zjwIAlgScXT/fvzL4A8VBQbTIYitDsBCLuhTJxPKlPUPUnSW3SmSm' +
'I8TFtltnfYpQtsIaBNb1nC7UUtbJBiVnvs1ka3De60ArswNDOSJgw' +
'k7GFVI9ln84baY3d6yIOOacR5XVTdpVmTpOPJnDK1VTwtwin/rhQT' +
'wJ4isYGMZ91Z2/8vKpmRJ5rIcJwHYMoqHDk6aaljsA9m9AHdbEnII' +
'yyjqmhUOnNBteUAFNuWyMj6sLFQWPx3UMlcpwtW7WrKZKbjKVDRBB' +
'ShJcUoD4Zbf7ANerhokPCEY/LgDBgVdaPxUJjKQ8u6HlKJPsBXoxp' +
'hDR+GMlvuiTmH4TyfJJWnxadUVFddWpl2kmCBpD50JBuv31aZPOTB' +
'Fm5p008VjXVoKSwIhkD6Ayb3+kB6Q6bwR0AFFreRA1Tzjc1cxEiFg' +
'0L0ZdBrtpPBXJPTSMgQWFqMAXej7gm0aP6QckZDSFRwVfiXcl1ReF' +
'fK73E29mgxKcNpResQVoMQVxiKNBLyeBf5+jxfXRyqKImR7KKZxj+' +
'rpSoEGfLgfOtdbLzT18fjzer7dn2Se6ewwckq9A0N5NJUMKZgwi4j' +
'F/BjEE+brX8GA0nWJzA0Humfkce/hEcHfVZxf+ABu9DRoVM/x0i1W' +
'R2/Ph4BXIDcO5E+eYrgvCo26GEQrOKhq3AKqDqOZJ7teBe8PHx5+f' +
'31z8O37eNRvjo2nlN4lDCR0D14jApzqeZed8lQefA6+AcVQ5qj');

AddOnTerminate('FreeBMP'); //Leaks the bitmap.. OutOfMemory exception is thrown when ran too much..
//When testing scripts over and over, memory builds up, you need to restart simba/smart and continue where you left off.
//if you do SetupSRL, even worse.
end.

litoris

2012-11-23 08:50:21

From: Brandon
Too buggy. Takes forever to compile. XOR doesn't work 100% of the time.


You can make you own xor using and's and not's right?

Brandon

2012-11-23 08:53:47

From: litoris
You can make you own xor using and's and not's right?


With If statements yeah.

Chris

2012-11-23 11:42:40

From: Brandon
With If statements yeah.


function cXor(a, b: boolean): boolean;
begin
result := (a and not b) or (not a and b);
end;

or

function cXor(a, b: boolean): boolean;
begin
result := (a or b) and not (a and b);
end;
^ a or b, and not a and b. basically the definition of xor ^.^

Can't test it on phone, but this should work :p

Edit: procedure -> function ofc xD