Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [SOLVED] No ID required for image/sprite?

Author
Message
Wolfsong73
User Offline
Joined: 22nd Aug 2020
Playing: FFXIV, Fall Guys, Redout
Posted: 23rd Mar 2021 12:23 Edited at: 23rd Mar 2021 12:24
Hi all,

So, following some advice I've seen in a few places, I've decided to look through code from other games made with AGK. Some of it has been helpful. However, some of it is raising new questions/confusion.

In particular, I'm looking at the code for "SantasBadElf", a game/code that came with the bundle I purchased. Specifically, it's in the "main_menu.agc" file.

g_iBackground = CreateSprite ( LoadImage ( "main_menu.jpg" ) )
g_iInstructions = CreateSprite ( LoadImage ( "instructions.jpg" ) )


I understand what this code is doing, it's creating a sprite and assigning its image in one statement, instead of two. That's neat.
What I'm confused on, though, is that every other tutorial I've seen indicates that an ID has to be assigned to each image and sprite, as that's how they're referenced by other commands. I'm assuming in this case, the background and instructions can/would be called by their respective variable name... And that, too, makes sense. Actually, assigning IDs to each image/sprite is something I hadn't seen before AGK.

So.. my questions are:
Are IDs optional for Sprites/Images? Are they situational?
Why are they not assigned in this case?

Thanks!

The author of this post has marked a post as an answer.

Go to answer

Heavens
5
Years of Service
User Offline
Joined: 10th May 2015
Location:
Posted: 23rd Mar 2021 12:52
This post has been marked by the post author as the answer.
This is the best way to manage resource ID's in my opinion, let AppGameKit do it for you.

Most Create functions (CreateSprite, CreateText...) have two versions one where you can tell it what resource number to use and then the other as above returns an integer that will be above 100,000 and is guaranteed to be unique (as long as you don't manually create an ID over 100,000)

Then for the rest of your code you don't have to care what resource number is assigned to what sprite you can just call g_iInstructions or g_iBackground or what ever you called the variable.

In the code if you put Print(g_iInstructions) or print(g_iBackground) you would see the number AppGameKit is using.

I never use the manual method.
Virtual Nomad
Moderator
15
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd Mar 2021 12:59
Quote: "Are IDs optional for Sprites/Images? Are they situational?
Why are they not assigned in this case?"

ID's are considered optional but if you plan on referencing them (ever) again, you'll need an ID to do that.
as far as assigning them manually or automatically, it's a personal preference.
while i believe most let AppGameKit assign the IDs (which, in theory, eliminates the chances of accidentally duplicating IDs, for example), some do prefer to do it themselves.
[My Itch.io Home] [Now Playing]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
Wolfsong73
User Offline
Joined: 22nd Aug 2020
Playing: FFXIV, Fall Guys, Redout
Posted: 23rd Mar 2021 14:49
@Heavens

Thank you for that explanation!

I think I prefer that approach, too. Give them meaningfully named variables, and let the language do the ID stuff.

Login to post a reply

Server time is: 2021-04-14 09:53:31
Your offset time is: 2021-04-14 09:53:31