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.

Author
Message
sprcoll
11
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 14th Jan 2023 20:19
Hello all together, i would be happy if some wants to help.
For many games i need different start positions for different levels. I have found a method to handle that but i want to know if this is a good method. A little example:

do


With this i can move the sprites with setspriteposition, because if i wouldn´t use the flag in every frame the x position is set to 400. Is this professional or are there besser methods? Thanks for helping.
eejit
6
Years of Service
User Offline
Joined: 25th Mar 2017
Location:
Posted: 15th Jan 2023 13:31 Edited at: 15th Jan 2023 13:43
Would the starting position for every level _always_ be 400, 400 ?

There are multiple ways to approach this - but first I would ask, are you going to hardcode all the different level information into the game itself ? This will work ok for a small game, but could be a limitation later.
I would recommend think about maybe it would be a good idea to come up with a layout that can let you store the level information in a separate file (including starting positions), that the game can read in.
I'm not sure I would use a onetime flag just to set the starting position, it might be a better idea to have a function that gets called when the player starts a new level - the position can be set there for example.

What does 'flag' really mean ? Is it the level your on, or it's 'I just started this level' it's 1, otherwise it's 2 - it's hard to tell the meaning with a generic name.

<edit> Oh "different start positions for different levels" I just re-read Are you on the AppGameKit discord server ?
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 15th Jan 2023 19:07 Edited at: 15th Jan 2023 19:29
this will build a type that u can use to control your level then build buttons then create a temp type as the same kind as the first, populate the temp with random variables
type then insert it into the real type. We then check for a button press and create the corresponding level.

if you are new to programming this will look confusing. think of a type as a phisical object like a shoe. A shoe has physical properties like width height color lace length and a position in real space x,y,z.

but you cant just type in shoe and the program know what u want. you must define this phisical object. then tell it what properties it has like color.
once you have an object u can acess its properties which will all be set to -1 because u did not define them.
so to set the properties of an object u must access the object shoe and its properties shoe.color
but what if we want a bunch of shoes? well we dont have to recreate the type/object because we already built it to we make an array type shoe as [] an array.

but we dont want a bunch of shoes that are built without width or height or color
so we build a temporary type temp as shoe . this says make a type that is the same as shoe but not an array or shoes. we can then fill in temp with all the property data we want the insert it into the shoe array.

in this case we make temp as level and fill it out. we then insert it into the type.

function are usefull as well they allow u to run code just like normal code but from anywhere. It also allows u to pass it data and then do something with that data.

function printnumber(mynumber)
print(mynumber)
endfunction

if you type printnumber(45) calls the printnumber function and passes it 45 it then mynumber is now equal to 45 inside the function so anycode in the function now treats it as a normal integer value of 45 in the code


functions, arrays and types are your friend. Learn them love them do not avoid them. persue them at all costs. When your skills get better you will find that u dont use agk command anymore but instead your own functions almost exclusively


sprcoll
11
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 15th Jan 2023 19:22
Thanks for your reply.

I want to use functions for the different levels, but there i think i have to work similar. I give the starting position into the functions and call it inside the do loop. So, i guess without to declare a variable and increase the variable in the same frame it don´t work.
This method is not so complex, for every level i need 2 lines and the starting positions. I have ask for a different method, because i am always interested whether my code is good or not so good, to get a better programmer.




sprcoll
11
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 15th Jan 2023 19:25
Thanks smerf, i will look at your code tomorrow.

Login to post a reply

Server time is: 2024-03-04 02:52:37
Your offset time is: 2024-03-04 02:52:37