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] Array sprite create

Author
Message
FetVil
5
Years of Service
User Offline
Joined: 16th Apr 2019
Location:
Posted: 1st May 2019 10:24 Edited at: 1st May 2019 10:50
I want to create a function that will display, for a start, output the amount of money with sprites every digit, but the program constantly gives errors, no matter how I change it.
Here is a sample program code, as it should look at the idea.

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

Go to answer

JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 1st May 2019 11:17 Edited at: 1st May 2019 11:23
This post has been marked by the post author as the answer.
Hey Fet, I can point out a few things for you that I can see right away that would cause some errors, though in order to make it work for what you need, I'm not sure I can help unless you post how, where, and when you're calling the function.

+ First off, the "X" function variable isn't being used. Is it suppose to be, and/or why? If your not calling the function as Money1(integer#), then just delete it.

+ The first loop for i=1j=1through10, you load images and create sprites 20-110. This will cause an error to occur, as in image/sprite already exist because on the next loop, i=2 j=1through10, you attempt to load and create images/sprites 30-120, that means 8 already exist. This would continue for each loop as you'll have 8 duplicates each loop until it's complete.

+ The variable Money is used in your function, you may be getting an error here for either you haven't declared the variable as a Global, or if not, you need to add the variable to your function so when you call it you'll need to input the variable you want the function to use. Example:

Declare Function:


Call Function:


edit: this function obviously won't compile and work, it's just an example of how to edit your function code for those specific lines of code and how you'd call the function in order for it to use the variable.

+ Last thing I can point out without seeing the rest of your code that uses this function..when setting the sprite position you're using 100 for x and 0+i*50 for y. This will cause the first ten sprites to stack on top of each other 50 units from the top. The next 10 will be stacked 100 units from the top(hoping your using pixels and not the percentage system or the rest of the sprites will be off screen). Next 10 will be 150 units from top, than next 200, than 250...ect, ect...

If we can see more code, where this function is used and how, I'm sure myself or others can help you get a simple function working. While you do that and wait for a response, look in the help files how to create User Defined Types , located under Principles. This will come in handy when getting a working function together, as well as keeping your code clean, easy to read and later debug if necessary.
FetVil
5
Years of Service
User Offline
Joined: 16th Apr 2019
Location:
Posted: 1st May 2019 13:48
X I use so that when I invoke any variable, I convert to x. Do not register in the function "Money", but for any other variable to work.
I got the function of creating a sprite and its position.

LoadImage(1,"0.png")
LoadImage(2,"1.png")
LoadImage(3,"2.png")
LoadImage(4,"3.png")
LoadImage(5,"4.png")
LoadImage(6,"5.png")
LoadImage(7,"6.png")
LoadImage(8,"7.png")
LoadImage(9,"8.png")
LoadImage(10,"9.png")
for i=1 to 10
for j=1 to 10
CreateSprite(j+i*10,j)
SetSpritePosition(j+i*10,-50+i*50,0)
next j
next i

And used the sprite appearance

function Money1(X)
for i=1 to 10
for j=1 to 10
if mod(X,10)=-1+j then SetSpriteVisible(j+i*10,1) else SetSpriteVisible(j+i*10,0)
next j
X=Fmod(X,10)
next i
endfunction

Call Function:

FetVil
5
Years of Service
User Offline
Joined: 16th Apr 2019
Location:
Posted: 1st May 2019 13:54
I looked at what I did wrong and how you advised to do it and everything finally turned out. Thank!
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 1st May 2019 16:38
Hah wow, good job! It's always a great feeling when people are able to go through their code and finally figure out their problem.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 1st May 2019 16:50
@Fetvil
Its always great when things work out, I noticed the way you was loading images
and thought that could be replaced with 3 lines of code

fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk

Login to post a reply

Server time is: 2024-11-23 08:06:18
Your offset time is: 2024-11-23 08:06:18