Control Structures – Talk

From Bohemia Interactive Community
Jump to navigation Jump to search
(More than one statement (SQS syntax - deprecated))
(Reinstate the dedicated pages?)
Line 1: Line 1:
Tried "if" and "switch" structures. "If" examples are wrong here! They don't work, because each block '{ }' must end with ';'. Am I right?
==Reinstate the dedicated pages?==
 
I think this page is very useful to give people an overview of the different control structures, and we should definitely keep it. But I think we should '''also''' have the dedicated pages we used to have for each specific command. That way we have a proper place for notes and discussions for the specific commands (which wouldn't quite fit in here). --[[User:Kronzky|Kronzky]] 00:47, 15 January 2007 (CET)
Also I can't get "switch" to work , anyone know how to use it? These examples are not working... --[[User:Messiah2|Messiah(UA)]] 12:19, 25 December 2006 (CET)
 
:1. yes that's true if used in [[SQF syntax]] scripts or functions. The structures are like any [[Statement]]: If used in [[SQF syntax]] scripts or functions, you have to add the semicolon ";" (except if you want to use the structure as return value of the function). Should we add the semicolons in the examples?
 
:2. I just noticed that there doesn't seem to be a ":" after "default". Also, it could be that you ''must'' include a default block, even if empty. Could you test that, maybe?
 
:Apart from that, what are your errors? Take care that you have to write control structures into a single line if used in [[SQS syntax]] scripts. --[[User:Hardrock|hardrock]] 15:01, 25 December 2006 (CET)
 
::A default block isn't necessary. --[[User:TeRp|TeRp]] 15:10, 25 December 2006 (CET)
 
:: AFAIK Control structures are intended for SQF. If so, then it would be definitely right to add semicolons in examples! Cocerning "switch", I was writing sqf and I can confirm, that default block is not necessary, I tried with and without it. And I can't write exact error right now (i'm at work), but I remember that something was wrong near "(VARIABLE) do {". I'll check it in the evening today and post here exact error. --[[User:Messiah2|Messiah(UA)]] 11:11, 26 December 2006 (CET)
 
:: Figured it out. That was my bad and switch is working right now, but anyway example is missing one semicolon. My mistake was that I wrote "default:" automatically and I didn't notice, that "default" is right! So 100% working code is --[[User:Messiah2|Messiah(UA)]] 20:32, 26 December 2006 (CET)
      switch (VARIABLE) do
      {
        case VALUE:
        {
        };
        default
        {
        };
      };
 
::: Rgr. Thanks for the info, I will add semicolons to the examples for clearer understanding. --[[User:Hardrock|hardrock]] 14:42, 27 December 2006 (CET)
 
[[step]] command should be added to list --[[User:T D|T_D]] 15:41, 25 December 2006 (CET)
 
: Rgr. Thanks for the hint. --[[User:Hardrock|hardrock]] 14:42, 27 December 2006 (CET)
 
== More than one statement (SQS syntax - deprecated) ==
 
Do you think this block really belongs here? If so, I'd recommend to alter the look.
 
First of all,
 
if (CONDITION) then {goto "label")}
#label
  statement1
  statement2
  statement3
 
is not really exact. label will be executed in any way here. To avoid that, you'd had to move label to the end of the file and add another label on after the conditional structure. Then, I'd recommend the simpler if-construct of [[SQS syntax]] here. The code then looks like that:
 
? CONDITION : goto "label"
#labelend
OTHER CODE
exit
#label
  STATEMENT
  ...
  goto "labelend"
 
Another version of writing this down is:
 
?!CONDITION : goto "labelend"
  STATEMENT
  ...
#labelend
 
which is clearer for short if-blocks. Same counts for if-else constructs
 
?!CONDITION : goto "labelelse"
  STATEMENT
  ...
  goto "labelend"
#labelelse
  STATEMENT
  ...
#labelend
 
Another matter why I'm not sure whether this belongs here is that "Control Structures" are [[Statement|statements]], as mentioned on top. Thus this is not really a control structure since it isn't a statement. This could leave to confusion.
 
Solutions could be to open a page with Tips for SQS syntax or to expand the page of [[SQS syntax]] itself.
 
--[[User:Hardrock|hardrock]] 14:54, 27 December 2006 (CET)

Revision as of 01:47, 15 January 2007

Reinstate the dedicated pages?

I think this page is very useful to give people an overview of the different control structures, and we should definitely keep it. But I think we should also have the dedicated pages we used to have for each specific command. That way we have a proper place for notes and discussions for the specific commands (which wouldn't quite fit in here). --Kronzky 00:47, 15 January 2007 (CET)