Jump to content
AC Tool Forums

Recommended Posts

In unit2 I remove the other uses, bu when I am saving the project, they are coming back automatically.

Thank you very much Wabbit, you are amazing!

Share this post


Link to post
Share on other sites

try saving each unit in the project with its own name, File > Save As. Then re-save the project and File > Close All.

Once you have done that. Try reloading the project. Both of the Unit tabs should show the name of the Unit file. And your second Unit file should be as it was saved.

If not, close Divide and rerun it. Then try to see if the project loads up as it should.

Share this post


Link to post
Share on other sites
uses
 divide;

var
   x;




begin

      if 10 > 6 then
   begin

          MousePos(646, 359);

  delay (1);
   else

     if 5 > 6 then
   begin
       MousePos(1081, 396);

       else
       if 8 > 6 then
   begin
MousePos(28, 411);
else
    delay (1);

   end

   end


  end

end



I get this message: unit unit1: Unkown identifier or variable is not declared: 'else'.
Source position: 18,7.

 

Share this post


Link to post
Share on other sites

While I await for your answer to the question in my previous post.

Three this about the posted code sticks out.

  • you defined a variable x, but then you didn't use it.
  • you are not ending those lines of code that require it with the semi-colon (';').
  • and you are not using the IF statements correctly.

Share this post


Link to post
Share on other sites

Yes the same format. The x was there because I like to have a constant for future use. What is wrong with my if statements?

Edited by minimx

Share this post


Link to post
Share on other sites

Well, it is very hard to read. I can't tell what goes with what IF statement. And it is the main reason for the error that you are getting. So I would suggest that you reformat the code in the Divide before posting it.

  1. Remove all empty lines.
  2. In the Main block remove all the spaces at the beginning of each line. And use the Tab key to indent each line.
  3. Use the Tab key to indent each level of block of code.
    Like the following.
    begin // Level 0
      begin // Level 1
        begin  // Level 2
          begin // Level 3
            // Level 4
          end;  // Level 3
        end;  // Level 2
      end;  // Level 1
    end;  // Level 0
    
    And so on... and so forth...

     

  4. If for some reason Divide it auto-indenting the blocks of code to something like the above. Then just go and fix it by performing #2 and #3 above.
  5. If the Tab key still does not give the proper indenting. Then use the Space key to perform the indenting. Use either 2 spaces for each Tab, or use 4 spaces for each Tab.
  6. Divide is set to use 2 spaces for each Tab.

 

Share this post


Link to post
Share on other sites

I'll talk about the semi-colon here.

In Pascal, and Divide, the semi-colon signals the end of a statement. And as such you must place a semi-colon at the end of a statement or line of code.

There are exceptions to this. Those exceptions are:

  • Comment blocks, you do not put a semi-colon at the end of each line in a comment block.
    Comment blocks are comments that can be on a single line. Or they can span multiple lines.
    There are two types of Comment blocks:
    • Those start with { and end with }.
    • And those that start with (* and end with *).
  • Line Comment, is a comment on a single line. It can be by itself on a line. Or it can be after a statement.
    Like the following:
    // This is a Line comment.
    MousePos(23, 35); // This is a Line comment after a statement.

     

  • You do not put a semi-colon at the end of a line/statement if the line/statement only has, or ends with, of one of the following keywords:

    • uses
    • var
    • const
    • begin
    • then
    • do
    • else
    • of
    • (There might be others, but at the moment I can't think of them.)

Now, when you place a Line Comment at the end of a statement. Unless the statement ends with any of the previously mentioned key words. You must use a semi-colon before you start the Line Comment. See the Line Comment examples above.

 

Share this post


Link to post
Share on other sites

Now, I'll talk about code blocks.

In Pascal, and Divide, code blocks are blocks of code that belong to a Procedure/Function or to a statement.

These code blocks start with the begin key word. And they end with the end keyword.

Example: Procedure and Function -

procedure SomeProcedure
begin
  // Code block
end;

function SomeFunction
begin
  // Code block
end;

 

Example: FOR statement -

for i := 0 to 5 do
begin
  // code block
  b := 13 * i;
  TimeStamp('b: '+IntToStr(b));
end;

Example: WHILE statement -

while i < 32 do
begin
  // code block
end;

Example: IF statement -

if myString = 'This is a test' then
begin
  // code block
end;

 

Now, there are certain statements (like repeat...until, case statements, etc) where you do not use a begin, or a end, or both a begin and a end, statement.

There is also one exception to beginning and ending a block of code with the begin and end keywords. The exception to this, is when the code in the cold block is a single statement. Then you do not have to use the begin and end keywords.

Example: FOR statement -

for i := 1 to 15 do
  TimeStamp('i: '+IntToStr(i));

 

Share this post


Link to post
Share on other sites

Now, for the issues with the IF statements in your script.

There is two things wrong with your IF statements. I'll talk about the first one here:

The first issue is the conditional expression being used for each IF statement.

With the conditional expression for the first IF statement. The second IF statement will never be executed. Then if by some miracle the second IF statement is evaluated. Then MousePos(1081, 396) statement will never be executed. And with the third statement. The delay(1) statement will never be executed.

That is if I have read that portion of your code correctly. It is so hard to read that section of the script because of the formatting.

 

That is why I suggested that you go and reformat the script in Divide. To make it more readable for others.

What I would suggest is that when you start a IF statement. That you first do the if and its conditional expression. Then open the code block with the begin on the very next line. And then immediately put the closing end on the next line. Then after your open and close the code block. Add in the code that is to be executed in that code block.

Share this post


Link to post
Share on other sites

Now the second part of what's wrong with your IF statements.

As I mentioned in the previous post. You need to place the keywords begin and end around a block of code that belongs to a IF statement.

But in your IF statements, you begin each IF statement code block with a begin. But, you never end the code blocks with an end. That is why you are getting the error message. Divide's script engine is expecting to find an end before it finds an else, just like in Pascal.

 

Now in Pascal, and in Divide, IF statements can be written in several different ways.

The first way of writing a IF statement. Is an IF statement that has code that is only executed if the conditional expression is TRUE.

Example 1:

If HP <= 43 then
begin
  TimeStamp('We need to heal.');
  MousePos(65, 258);
end;

 

Now, we will look at a IF statement that will execute code if its conditional expression is TRUE and if it is FALSE.

Example 2:

if HP <= 43 then
begin
  TimeStamp('We need to heal.');
  MousePos(65, 258);
end
else
begin
  TimeStamp('We do not need to heal.');
  Delay(500);
end;

 

Here we will look at at IF statement that will execute code only if its conditional expression is TRUE. But it only has one statement.

Example 3:

if HP = 0 then
  TimeStamp('I'm sorry, but we are dead.');

And here we will look at a IF statement that will execute code if its conditional expression is TRUE and if it is FALSE. But, it only has one statement in both the TRUE block and the FALSE block.

Example 4:

if IsObject(TestObject, 34, 185) then
  TimeStamp('The object was found.')
else
  TimeStamp('The object was not found.');

 

Now in Pascal, as well as Divide, the statement right before an else, within a IF statement, does not end with a semi-colon (';'). And as you can see from Example 2 and Example 4. The statement just before the else does not end with a semi-colon. In Example 2 the statement just before the else is the end. And in Example 4, the line before the else is the TimeStamp('The object was found.').

Guess what? You can mix IF statements with single statements and a block of statements.

Example 5:

for HP <= 43 then
begin
  TimeStamp('We need to heal.');
  MousePos(65, 258);
end
else
  TimeStamp('We do not need to heal.');

Example 6:

if HP = 0 then
  TimeStamp('I'm sorry we are dead!')
else
begin
  TimeStamp('Do we need to heal?');
  CheckHeal;
end;

 

And of course, you can nest a IF statement within a IF statement's TRUE and/or FALSE block.

if conditional_expression then
begin
  if conditional_express then
  begin
	// TRUE code block
  end;
end
else
begin
  // FALSE code block.
end;

 

As you can see. There is lots of ways to write a IF statement. You can use any one of, or any combination, of the examples above to create your if statement(s). As long as you follow the rules about using begin and end. And that you also follow the rules about the statement just before the else. Otherwise you will get a

Share this post


Link to post
Share on other sites
14 hours ago, minimx said:

uses
 divide;

var
   x;




begin

      if 10 > 6 then
   begin

          MousePos(646, 359);

  delay (1);
   else

     if 5 > 6 then
   begin
       MousePos(1081, 396);

       else
       if 8 > 6 then
   begin
MousePos(28, 411);
else
    delay (1);

   end

   end


  end

end



I get this message: unit unit1: Unkown identifier or variable is not declared: 'else'.
Source position: 18,7.

 

Wabbit, you are AMAZING MATE!!! I love you! I love you!

this one works:


 

uses
 divide;

begin //lvl 0
  if 10 > 11 then //lvl 1
  begin
  delay (1000);
  MousePos(646, 359);
  delay (5000)  ;
  end;  // lvl 1
  else
  begin  //lvl 1,5
  bell;
    if 5 > 6 then
    begin      //lvl 2
    MousePos(1081, 396) ;
    delay (1000)  ;
    end;    // lvl 2
    else
    begin   //lvl 2,5
      if 8 > 6 then
      begin     //lvl 3
      MousePos(28, 411);
      delay (5000)  ;
      end;  // lvl 3
      else
      begin   //lvl 3,5
      delay (1000)  ;
      end;     //lvl 3,5
    end;     //lvl 2,5
  end;       //lvl 1,5
  delay (1000);
  MousePos(325, 553);

end;  //lvl 0




In Divide you can have an else inside an else, but you have to be really organized! You are amazing, thanks!

Share this post


Link to post
Share on other sites

Okay, You did great with the formatting. And it is good that you finally got the script to work. But, your formatting can use a tiny bit more work.

So, look at the following of your last script:

uses
 divide;

begin
  if 10 > 11 then
  begin
    delay(1000);
    MousePos(646, 359);
    delay(5000);
  end
  else
  begin
    bell;
    if 5 > 6 then
    begin
      MousePos(1081, 396);
      delay(1000);
    end
    else
    begin
      if 8 > 6 then
      begin
        MousePos(28, 411);
        delay(5000);
      end
      else
      begin
        delay(1000);
      end;
    end;
  end;
  delay(1000);
  MousePos(325, 553);
end;

Now it you compare this script with yours, you should see the differences. But if not, then here are the differences:

  1. I removed the Line comments.
  2. And I removed the semi-colon (';') from the end of the end statements that are on the lines before the else statements. This follows the rules for IF statements as laid out in Pascal, and in Divide.
  3. You had Delay commands with extra spaces in the command. You placed extra spaces before the ( and after the ).
    As examples:
    Delay (1000);
    Delay (5000) ;

    You do not need to put extra spaces in like that.
  4. And I have properly indented the code to reflect the four different levels.


If you can't tell the 4 levels of indentation, then see the following:

Spoiler

uses
 divide;

//lvl 0 = 0 Tabs or 0 spaces
begin
  //lvl 1 = 1 Tab or 2 spaces
  if 10 > 11 then
  begin
    //lvl 2 = 2 Tabs or 4 spaces
    delay(1000);
    MousePos(646, 359);
    delay(5000);
  //lvl 1 = 1 Tab or 2 spaces
  end
  else
  begin
    //lvl 2 = 2 Tabs or 4 spaces
    bell;
    if 5 > 6 then
    begin
      //lvl 3 = 3 Tabs or 6 spaces
      MousePos(1081, 396);
      delay(1000);
    //lvl 2 = 2 Tabs or 4 spaces
    end
    else
    begin
      //lvl 3 = 3 Tabs or 6 spaces
      if 8 > 6 then
      begin
        //lvl 4 = 4 Tabs or 8 spaces
        MousePos(28, 411);
        delay(5000);
      //lvl 3 = 3 Tabs or 6 spaces
      end
      else
      begin
        //lvl 4 = 4 Tabs or 8 spaces
        delay(1000);
      //lvl 3 = 3 Tabs or 6 spaces
      end;
    //lvl 2 = 2 Tabs or 4 spaces
    end;
  //lvl 1 = 1 Tab or 2 spaces
  end;
  delay(1000);
  MousePos(325, 553);
//lvl 0 = 0 Tabs or 0 spaces
end;

 

As you can see, the beginning of each Line Comment is the level of indentation. And each level of indentation sections off each block of code. Making it easier to read the code that you have written.

 

So You need to start formatting your code like this. And don't forget about the rules for IF statements, as I had already told you in my previous post.

Share this post


Link to post
Share on other sites
4 hours ago, The WABBIT said:

And I removed the semi-colon (';') from the end of the end statements that are on the lines before the else statements. This follows the rules for IF statements as laid out in Pascal, and in Divide.

This is really important. Thank you soo much! Ok, I will try to improve and make my codes as clean an as organized as yours!

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and to our Privacy Policy.