Difference between revisions of "Set.loop"

From AGI Wiki
Jump to navigationJump to search
(Created page with "Set.loop   == <br />Syntax == <blockquote><code>set.loop(oA,B);</code></blockquote>   == Description == The current loop of object oA is set to B. If an invalid...")
 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
Set.loop
+
The '''set.loop''' command assigns a loop to a screen object.
  
&nbsp;
+
== Syntax ==
  
== <br />Syntax ==
+
set.loop([[screen object|obj]] oA, [[number|byt]] LOOP);
  
<blockquote><code>set.loop(oA,B);</code></blockquote>
+
== Remarks ==
  
&nbsp;
+
The current [[loop]] of [[screen object]] '''oA''' is set to '''LOOP'''.
== Description ==
 
  
The current loop of object oA is set to B. If an invalid loop number is given, the interpreter generates an error. If the current cel of the object is greater than the last cel in loop B, then the current cel is set to 0.
+
A [[View Resource (AGI)|view]] must be be assigned to the object first. If a view is not assigned, AGI raises [[trappable error #6]]. If '''LOOP''' is not a valid loop number, i.e. it exceeds the maximum number of available loops in the view, AGI raises [[trappable error #5]].
  
&nbsp;
+
Be aware that there is a bug in all versions of AGI affecting the check for valid loop numbers. AGI only returns [[trappable error #5]] if the value of '''LOOP''' is GREATER than the total number of loops in the view. However, since loops are zero based (first loop is 0, second loop is one, etc.), the last valid loop would be total loop count minus one. If '''LOOP''' is EQUAL to the loop count, AGI doesn't raise an error, but the loop number is actually invalid, and using it will almost always end up in [[crashing AGI]].
== See also ==
 
  
* <code>[[set.loop.v]]</code>
+
When the loop changes, AGI checks to see if the current [[cel]] value of the screen object is now greater than the last cel in newly assigned loop. If it is, the cel is reset to 0; if not the screen object's cel value is not changed.  
* <code>[[current.loop]]</code>
 
* <code>[[number.of.loops]]</code>
 
* <code>[[set.cel]]</code>
 
* <code>[[set.cel.v]]</code>
 
* <code>[[Cycling objects]]</code>
 
  
&nbsp;
+
== Possible Errors ==
  
[[Category:Object Commands]]
+
In [[version]] 2.089 only, AGI raises [[trappable error #4]] if object number '''oA''' is invalid. In all later versions, AGI does not check that object number '''oA''' is a valid object. If it is not, this command will overwrite other data on the [[memory heap]], which may cause unexpected results, including possibly [[crashing AGI]].
[[Category:View Commands]]
+
 
 +
== Example ==
 +
 
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="agi">
 +
[ typical code to add a static view
 +
animate.obj(o1);
 +
load.view(8);
 +
set.view(o1, 8);
 +
set.loop(o1, 1);
 +
set.cel(o1, 2);
 +
position(o1, 20, 132);
 +
stop.cycling(o1);
 +
draw(o1);
 +
</syntaxhighlight>
 +
 
 +
== Technical Information ==
 +
 
 +
{| border="1" cellpadding="2"
 +
| style="background-color: #efefef" width="200" | '''Required Interpreter Version:'''
 +
| width="175" | Available in all AGI versions.
 +
|-
 +
| style="background-color: #efefef" | '''Byte-Code Value:'''
 +
| 43 (0x2B hex)
 +
|}
 +
 
 +
== See Also ==
 +
 
 +
'''[[set.cel]]'''<br />
 +
'''[[set.cel.v]]'''<br />
 +
'''[[set.loop.v]]'''<br />
 +
'''[[set.view]]'''<br />
 +
'''[[set.view.v]]'''<br />
 +
[[Category:Commands]]<br />

Latest revision as of 13:17, 21 April 2019

The set.loop command assigns a loop to a screen object.

Syntax

set.loop(obj oA, byt LOOP);

Remarks

The current loop of screen object oA is set to LOOP.

A view must be be assigned to the object first. If a view is not assigned, AGI raises trappable error #6. If LOOP is not a valid loop number, i.e. it exceeds the maximum number of available loops in the view, AGI raises trappable error #5.

Be aware that there is a bug in all versions of AGI affecting the check for valid loop numbers. AGI only returns trappable error #5 if the value of LOOP is GREATER than the total number of loops in the view. However, since loops are zero based (first loop is 0, second loop is one, etc.), the last valid loop would be total loop count minus one. If LOOP is EQUAL to the loop count, AGI doesn't raise an error, but the loop number is actually invalid, and using it will almost always end up in crashing AGI.

When the loop changes, AGI checks to see if the current cel value of the screen object is now greater than the last cel in newly assigned loop. If it is, the cel is reset to 0; if not the screen object's cel value is not changed.

Possible Errors

In version 2.089 only, AGI raises trappable error #4 if object number oA is invalid. In all later versions, AGI does not check that object number oA is a valid object. If it is not, this command will overwrite other data on the memory heap, which may cause unexpected results, including possibly crashing AGI.

Example

Code:

<syntaxhighlight lang="agi"> [ typical code to add a static view animate.obj(o1); load.view(8); set.view(o1, 8); set.loop(o1, 1); set.cel(o1, 2); position(o1, 20, 132); stop.cycling(o1); draw(o1); </syntaxhighlight>

Technical Information

Required Interpreter Version: Available in all AGI versions.
Byte-Code Value: 43 (0x2B hex)

See Also

set.cel
set.cel.v
set.loop.v
set.view
set.view.v