Page 1 of 1 1
Topic Options
#155165 - 2006-01-12 08:47 PM Include/Call & Number
Yoann Offline
Lurker

Registered: 2006-01-12
Posts: 2
Hello,

I start in KiXtart and I have some questions.

1. What's the difference between include and call functions ?
2. How can i get the result of a simple division (in floating point format) ?


Thanks.

Top
#155166 - 2006-01-12 09:17 PM Re: Include/Call & Number
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
division = cdbl()
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#155167 - 2006-01-12 10:26 PM Re: Include/Call & Number
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yoann, read the manual.
Quote:


INCLUDE is most useful when pre-tokenizing files: include-files are effectively merged with the script containing the INCLUDE statements and the end-result is stored as a single pre-tokenized file.



Quote:


Remarks
Note that INCLUDE statements are processed during the pre-processing phase of KiXtart at which point macros, variables and functions are not yet available. As such, INCLUDE only supports a single, flat string and you can not use macros, variables or functions in this string.

Script code in INCLUDE files that is not inside user-defined functions cannot contain labels and you can not jump into or out of an INCLUDE file.



_________________________
!

download KiXnet

Top
#155168 - 2006-01-12 10:58 PM Re: Include/Call & Number
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
This is a great question. But there's more to the story ... the "scope" rules for included files versus called files are different. Called and included are "kinda" the same, yet very different.

Think of include files as code that is "inserted" or "injected" right into your main code, right where you put the include. Where as called files are "jumped to" and maintain a seperate scope.

Two important differences (for example) are DIM'ed variables and the EXIT statement.

Variables DIMed in a called script are not visible to the parent script that "called" it - the scope is local to the called script. Variables DIMed in an included script are available to the "parent" script - because the included script was simply injected right into the parent script, and the interpretor treated it as part of the main script.

Using the EXIT command in a called script exits the called script (scope again) ... using EXIT in an included script causes the parent script to exit (because again, the included script gets processed as if it was the main script).

Confusing I know ...

-Shawn

Top
#155169 - 2006-01-12 11:17 PM Re: Include/Call & Number
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Let's add some confusion.

Exit won't exit/quit the script it it's inside a UDF or another called script

Top
#155170 - 2006-01-12 11:19 PM Re: Include/Call & Number
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
EXIT wont exit the main script, if its inside a UDF inside an included script. My head hurts.
Top
#155171 - 2006-01-12 11:22 PM Re: Include/Call & Number
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Quote:

EXIT wont exit the main script, if its inside a UDF inside an included script. My head hurts.







It won't from called either

Top
#155172 - 2006-01-12 11:25 PM Re: Include/Call & Number
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Anyway bottom line: Take Jooel's advise (from the manual) - don't use INCLUDED scripts unless your planning to tokenize them.
Top
#155173 - 2006-01-12 11:26 PM Re: Include/Call & Number
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Agreed. I would not use INCLUDE until you have more time and experience under your belt with KiXtart.
 

Top
#155174 - 2006-01-13 06:07 AM Re: Include/Call & Number
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol.
well, guess the easy answer to the difference is then that include includes the given kixtart script source as part of the script whereas call treats the file as single subscript as if it was under gosub.

anyway, I don't see no reason avoiding neither one of them.
when using include, the script starts some 20ms slower and using call this same effect happens during execution but takes slightly longer.
_________________________
!

download KiXnet

Top
#155175 - 2006-01-13 10:27 AM Re: Include/Call & Number
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

division = cdbl()




Careful, that's not quite the full story.

The result of
Code:
CDbl(3/2)


Is "1.0" - it is floating point, however it is probably not the result you were looking for.

The result of
Code:
CDbl(3)/2


Is "1.5", which is probably what you are after.

Top
#155176 - 2006-01-13 05:06 PM Re: Include/Call & Number
Yoann Offline
Lurker

Registered: 2006-01-12
Posts: 2
Thanks, all.
Top
#155177 - 2006-01-14 08:12 PM Re: Include/Call & Number
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
For division - kixtart takes the 1st variable starting from the left as the primary format for both the final result & the individual calculation results. So if x=a/b then 'a' should be in floating point format. x=1.0*a/b will always return floating point and force a proper floating point division. I have not tested this but I think that x=cdbl(a/b) would return a floating point result but if 'a' is in integer format the division will be done using integer division.

PS: I missed page 2 & Richard had already answered it better & in more detail.


Edited by Jack Lothian (2006-01-14 08:15 PM)
_________________________
Jack

Top
#155178 - 2006-01-14 10:29 PM Re: Include/Call & Number
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you already have 2 pages?
you have only some 10 posts per page or what? huh...
_________________________
!

download KiXnet

Top
#155179 - 2006-01-18 03:04 AM Re: Include/Call & Number
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
Yes the 1st 10 posts fill my screen. Never used glasses until recently but even with my new glasses the big letters help.
_________________________
Jack

Top
#155180 - 2006-01-18 07:25 AM Re: Include/Call & Number
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol.
anyway, I've noticed that it's lot easier to follow up discussion when one uses flatmode and sets the "Total posts to show on one page when viewing a post in flat mode" setting to 40 or 50 in http://www.kixtart.org/ubbthreads/editdisplay.php?Cat=0

when more, the load time tends to get annoying with large threads.
_________________________
!

download KiXnet

Top
#155181 - 2006-01-20 03:35 AM Re: Include/Call & Number
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
Interesting the default posts dispayed is 20 but mine is set to 10. I don't remember setting it to 10 or the reason why I changed the default. I changed it to your suggestion. I will see how works. Thanks
_________________________
Jack

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2375 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.071 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org