Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
gurpreetsinghmatharoo committed Aug 8, 2024
1 parent 7cb26fd commit 281796c
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>asset_get_index</title>
<meta name="generator" content="Adobe RoboHelp 2020" />
<meta name="generator" content="Adobe RoboHelp 2022" />
<link rel="stylesheet" href="../../../../assets/css/default.css" type="text/css" />
<script src="../../../../assets/scripts/main_script.js"></script>
<script src="../../../../assets/scripts/main_script.js" type="module"></script>
<meta name="rh-authors" content="Mark Alexander" />
<meta name="topic-comment" content="Page explaining the function asset_get_index" />
<meta name="rh-index-keywords" content="asset_get_index" />
Expand All @@ -15,12 +15,12 @@
</head>
<body>
<!--<div class="body-scroll" style="top: 150px;">-->
<h1>asset_get_index</h1>
<h1><span data-field="title" data-format="default">asset_get_index</span></h1>
<p>This function gets the unique identifying index for a game asset from its name.</p>
<p>If the asset is not found, the function will return a value of -1, otherwise it will return the unique index id for the asset being checked. This id can then be used in other functions as you would any other index value, like the <a href="../Sprites/Sprite_Instance_Variables/sprite_index.htm"><span class="inline">sprite_index</span></a> or the <a href="../Paths/Path_Variables/path_index.htm"><span class="inline">path_index</span></a>, for example. Please note that although this function can be used to reference assets from strings (see example below), you should always make sure that the asset exists before using it otherwise you may get errors that will crash your game.</p>
<p>If the asset is not found, the function will return a value of -1, otherwise it will return the unique index ID for the asset being checked. This ID can then be used in other functions as you would any other index value, like the <span class="inline2"><a data-xref="{title}" href="../Sprites/Sprite_Instance_Variables/sprite_index.htm">sprite_index</a></span> or the <span class="inline2"><a data-xref="{title}" href="../Paths/Path_Variables/path_index.htm">path_index</a></span>, for example. Please note that although this function can be used to reference assets from strings (see example below), you should always make sure that the asset exists before using it otherwise you may get errors that will crash your game.</p>
<p> </p>
<h4>Syntax:</h4>
<p class="code">asset_get_index(name);</p>
<p class="code"><span data-field="title" data-format="default">asset_get_index</span>(name);</p>
<table>
<tbody>
<tr>
Expand All @@ -30,22 +30,24 @@ <h4>Syntax:</h4>
</tr>
<tr>
<td>name</td>
<td><span data-keyref="Type_String"><a href="../../../../../GameMaker_Language/GML_Overview/Data_Types.htm" target="_blank">String</a></span></td>
<td><span data-keyref="Type_String"><a href="../../../GML_Overview/Data_Types.htm" target="_blank">String</a></span></td>
<td>The name of the game asset to get the index of (a string).</td>
</tr>
</tbody>
</table>
<p> </p>
<h4>Returns:</h4>
<p class="code"><span data-keyref="Type_Asset"><a href="../../../../../The_Asset_Editors/The_Asset_Editors.htm" target="_blank">Asset</a></span> (any asset type)</p>
<p class="code"><span data-keyref="Type_Asset"><a href="../../../../The_Asset_Editors/The_Asset_Editors.htm" target="_blank">Asset</a></span> (any asset type)</p>
<p> </p>
<h4>Example:</h4>
<p class="code">var obj = asset_get_index(&quot;obj_Enemy_&quot; + string(global.Level));<br />
if obj &gt; -1<br />
<br />
if (object_exists(obj))<br />
{<br />
    instance_create_layer(random(room_width), random(room_height), obj, &quot;Enemy_Layer&quot;);<br />
}</p>
<p>The above code will get an object index from a string, and if that index exists, create an instance of the object in the game.</p>
    instance_create_layer(random(room_width), random(room_height), &quot;Enemy_Layer&quot;, obj);<br />
}
</p>
<p>The above code will get an object asset from a string, and if that asset exists, create an instance of the object in the game.</p>
<p> </p>
<p> </p>
<div class="footer">
Expand All @@ -55,7 +57,7 @@ <h4>Example:</h4>
<div style="float:right">Next: <a href="asset_get_type.htm">asset_get_type</a></div>
</div>
</div>
<h5><span data-keyref="Copyright Notice">© Copyright YoYo Games Ltd. 2023 All Rights Reserved</span></h5>
<h5><span data-keyref="Copyright Notice">© Copyright YoYo Games Ltd. 2024 All Rights Reserved</span></h5>
</div>
<!-- KEYWORDS
asset_get_index
Expand Down

0 comments on commit 281796c

Please sign in to comment.