Goto https://www.stucuk.netGoto https://www.atlanticaonlinewiki.comGoto https://www.game-requirements.com


Menu


It is currently Sat Sep 22, 2018 2:24 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Making certain functions accept 'list' (not only 'integer')
PostPosted: Sun Jun 14, 2009 8:10 pm 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1129
Location: Denmark
Is there anything more frustrating than finding out that the function you gonna use only accepts 'integer' and you have a massive list of persons the function must test? This is a solution to remake functions, that returns a boolean, to test a whole list instead of just an integer (= one person). E.g. the function IsInArea(integer, integer). Let's say we want to remake this function so it returns 'true' if all persons in the list is in the specified area, and 'false' if just one person isn't.

Code:
Function IsInAreaList(list,area);
     var c, counter;
     begin
          counter = 0;
          for c in list do
               begin
                    if IsInArea(c,area) then
                         begin
                              counter = counter + 1;
                         end;
               end;
          if list = counter then
               begin
                    result:=TRUE;
               end
          else
               begin
                    result:=FALSE;
               end;
     end;


Last edited by McBenn on Wed Jul 01, 2009 8:40 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Making certain functions accept 'list' (not only 'intege
PostPosted: Mon Jun 15, 2009 2:25 am 
Offline
Moderator
Moderator
User avatar

Joined: Fri Jan 13, 2006 6:20 pm
Posts: 2325
Location: Argentina
Great work! And btw: Long life Lego system! =D

_________________
-Aleph.

THE Very active person

"You can only do well at something if you put the time in. Doesn't matter what subject it is. You can't make a master piece over night."
Wise man Stu-


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 15, 2009 7:04 am 
Offline
OW Support Owner
OW Support Owner
User avatar

Joined: Wed Dec 28, 2005 11:13 pm
Posts: 5001
Location: UK, Scotland
Nice, thanks for sharing your code.

_________________
Image
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 15, 2009 11:11 am 
Offline
Soldier level 1
Soldier level 1
User avatar

Joined: Mon Nov 26, 2007 8:07 pm
Posts: 86
Location: Germany
nice :)

_________________
MEMORIES, A OWAR MOD, PLEASE TRY OUT


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 01, 2009 2:31 pm 
Offline
Original-War.Net Owner
Original-War.Net Owner
User avatar

Joined: Wed Jan 25, 2006 10:21 am
Posts: 2786
Location: Poland, Białystok
This is my optimized version of ur code:
Code:
function IsInAreaList(list,area);
    var integer;
    begin
        result=true;
        for integer in list do
            if not IsInArea(integer,area) then
                result=false;
    end;

enjoy!

Stu, I'd like to know how to break a loop in SAIL to fully optimize this code.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 02, 2009 6:23 am 
Offline
OW Support Owner
OW Support Owner
User avatar

Joined: Wed Dec 28, 2005 11:13 pm
Posts: 5001
Location: UK, Scotland
Same as Delphi. Break or Exit. Break exits the current loop. Exit compleatly exits the current function.

_________________
Image
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 02, 2009 9:10 am 
Offline
Original-War.Net Owner
Original-War.Net Owner
User avatar

Joined: Wed Jan 25, 2006 10:21 am
Posts: 2786
Location: Poland, Białystok
Thanks!
Here is the 100% optimized code:
Code:
function AreInArea(list,area);
    var integer;
    begin
        for integer in list do
            if not IsInArea(integer,area) then
                exit;
        result=true;
    end;


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 02, 2009 10:54 am 
Offline
Original-War.Net Owner
Original-War.Net Owner
User avatar

Joined: Sun Jan 01, 2006 4:56 pm
Posts: 419
Location: Eastern Europe
If you don't define "result" then I don't think it will automatically return false, but should return null. So if you test on whether the function result is false, who knows what might happen. So rather it should be like this I think:
Code:
function AreInArea(list,area);
    var integer;
    begin
        for integer in list do
            if not IsInArea(integer,area) then
            begin
                result=false;
                exit;
            end;
        result=true;
    end;

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 02, 2009 3:57 pm 
Offline
Original-War.Net Owner
Original-War.Net Owner
User avatar

Joined: Wed Jan 25, 2006 10:21 am
Posts: 2786
Location: Poland, Białystok
Well, I checked that and my code worked well. Seems like sending no value (NULL if you wish) is the same as sending 0/negative/false.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Original War is an RTS / RPG game by Altar Games
Original War Support is not part of Altar Games but is maintaining Original War for Altar Games

Privacy Policy