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 / Need help with arrays

Author
Message
Unseen Ghost
22
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 20th Feb 2018 02:07 Edited at: 20th Feb 2018 03:22
Hi,

I am building a app for the team I am on at work. The app I'm trying to make is fro keeping track of the work rotation of the team during work.

We work on an assembly line.

11 team members

9 line positions
1 teardown position
1 teamleader position

Teamleader is always the same person that doesn't change.

We start on a position in the morning and rotate to next position each break time. We usually have 4 rotations each day, on occasion we have 5 if we work longer hours.
I was thinking of setting it up in an array obviously using the Dim command. I'm not good with arrays and would like some suggestions on how to set it up

EDIT: I forgot to mention that some people on the team like to trade positions with another team member because they would rather do a different position than the one that they are currently suppose to do. Also sometimes multiple people are involved in a trade so everyone is happy. This is why I want to create an app that keeps track of where people are and the original rotation line up also.

For example:

original line up
pos 1 = Jon
pos 2 = Terry
pos 3 = Pat
pos 4 = Fred
pos 5 = Brian
pos 6 = Rich
pos 7 = Larry
pos 8 = Sam
pos 9 = Tom

Teardown = Lana

after some trades the current line up might look like this
pos 1 = Jon
pos 2 = Fred
pos 3 = Pat
pos 4 = Terry
pos 5 =Larry
pos 6 = Rich
pos 7 = Sam
pos 8 = Tom
pos 9 = Lana

Teardown = Brian

I want to keep track of the original rotation positions and the new switched positions also.
Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 9400 GT(PNY)1GB Video/500GB Western Dig. HD/Dark Basic Pro 7.4

No one cares how much you know until they know how much you care.
easter bunny
12
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 20th Feb 2018 04:29
To keep back of both the original layout and the switched layout you'll need to use two arrays.

As for manipulating the items in an array, you could perhaps do it with a couple of functions like these:



Hope that helps put you in the right direction

My Games - Latest WIP - My Website: Immortal.Digital - FB - Twitter
130,000 installs with AppGameKit and counting
Unseen Ghost
22
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 20th Feb 2018 13:32
Thanks easter bunny for your examples. It is a big help. I'm not really good with complex arrays just simple ones so far. I will study your snippet and work with it. I'll let you know if it works.
Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 9400 GT(PNY)1GB Video/500GB Western Dig. HD/Dark Basic Pro 7.4

No one cares how much you know until they know how much you care.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 20th Feb 2018 14:26
For simple arrays I found arrays easiest to understand when thinking of them like a book index.
I.e.
Dim chapter[10] as string
Means you will have 10 chapters and we can store each chapter title...
So
chapter[1] = "introduction"
chapter[2] = "first meet"
Etc

Now you may want to store the pages per chapter
Dim chapter_length[10] as integer
chapter_length[1] = 3 // 3 pages in chapter 1
Etc

Now if for some reason I wanted to swap two values around you store the first in a temporary variable and then swap it to the new position and then swap the other with the stored value.
So
Temp_length = chapter_length[1]
chapter_length[1] = chapter_length[4]
chapter_length[4] = Temp_length
Will swap chapter 1 and 4s lengths (not really logical for a book but you wanted to swap people so its the same principle).
Note, the order for swapping above is important, otherwise you can store both values before you swap to then just swap with the desired temp value.

This isn't the best way to define and use arrays in agk2 but it does work and will be more than fine for your purpose (plus its the easiest method to understand and use IMO compared to the newer version).
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Feb 2018 15:39
Quote: " I'm not really good with complex arrays just simple ones so far. "

This is pretty simple as far as arrays go, all you have is a small list that shifts around a little.

Quote: "Dim chapter_length[10] as integer"

Don't need DIM in AGK. Not sure if it's even in the command set anymore.

I'm not sure if this is exactly what you want. I assumed you want to rotate the original list of names as well as the modified list, but keep the original list in the same order. If that's the case, I used a UDT so we only have to manage a single array. And rotations affect both lists at the same time. Using the swap function will only switch employees in the temp list. And the rebuild function will copy the original order back to the temp list.

Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Unseen Ghost
22
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 20th Feb 2018 16:32 Edited at: 20th Feb 2018 16:37
Thank you smallg for your simple explanation of a more complex array than the simple lottery( 52, 6 ) example. I think I'm starting to understand it more.

So far I have only given in my first post above is the basic daily rotation information without other stuff like someone taking vacation day(s) or calling off sick and how it affects the rotation like who takes the position of the person off for the day(s).

Scheduled vacation day(s) I can work into it by looking at the vacation calendar and figuring out original rotation data in advance.
Plus there are days we don't have enough people on our team to cover all positions because of call offs so we get help from other teams that have extra people to lend out so we can fill the positions. I will probably make a string variable called help for that.
Also when we have enough people to have a teardown person and another line is short people they might use a person from our team to help them. I will make a variable called loan_out for that.

I'm going to have it so all members of our team can have the app and send a trade request to person(s) they want to trade with and they can accept it or deny it.

Also want people to be able to trade day(s) in advance lol.
So you can see how complex of an app it's going to be. Lol
Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 9400 GT(PNY)1GB Video/500GB Western Dig. HD/Dark Basic Pro 7.4

No one cares how much you know until they know how much you care.
Unseen Ghost
22
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 20th Feb 2018 18:10 Edited at: 20th Feb 2018 18:13
[/quote]This is pretty simple as far as arrays go, all you have is a small list that shifts around a little.[quote=]

I am seeing that now. In DBPand Classic, my brother does all the data work and I do the UI and 3d stuff. Arrays haven't been easy to understand for me until lately. I have just needed a more simple explanation from someone.

I'll be intensely working tonight on the arrays.
Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 9400 GT(PNY)1GB Video/500GB Western Dig. HD/Dark Basic Pro 7.4

No one cares how much you know until they know how much you care.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Feb 2018 21:43
Easiest way I can think of to explain it to someone, it's just a container of things, or collection. The things are the elements, the container is the array holding the elements. And a container can contain other containers (multi-dimensional array).

A bag of m&ms. The bag is the array, the candies are the elements. Now think of the box sitting on the shelf you grabbed that bag from. That box contains 20 bags, each bag contains 200 m&ms. (i'm guessing on quantities here).

If the m&m candies are integers, then a bag looks like: (a single bag of 200)

candy as integer[200]

The box on the shelf would look like: (20 bags of 200)

candy as integer[20][200]

And if you have a delivery truck carrying 5 boxes, that truck becomes a container as well. (1 truck, 5 boxes, 20 bags per box, 200 per bag)

candy as integer[5][20][200]

Each box, each bag, every last m&m is given a unique index to reference it. So say you want to pick the 117th m&m from the 3rd bag located in the 4th box.

oo_piece_of_candy = candy[4][3][117]

AGK supports what is known as staggered arrays, but for simplicity I'm not going to confuse you with them. And honestly, I've never had a need for such a structure myself anyway.


Once you understand arrays, you should look into understanding how to use UDTs (user-defined type). It's similar to a struct (if you're familiar with C++). A UDT is your own custom data type and, similar to a vector, can contain any number of primitive data types (integer, string, float). It can also include other UDTs or even arrays. In essence, a UDT is like an array in that it's a collection of things, only whereas an array is a collection of things of the same type, a UDT is a collection of 1 or more types.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Unseen Ghost
22
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 20th Feb 2018 22:40 Edited at: 20th Feb 2018 23:56
Quote: " not sure if this is exactly what you want. "


Edit: Every break time the original rotation line up moves to next highest position until you get to position 9 then you go to position 1.

Yes I need to keep track of the original rotation line up also because that is what most of all the trading is done from. If someone doesn't want to work one of their upcoming rotation positions they are originally suppose to work they can trade it away for a position they would rather work.
Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 9400 GT(PNY)1GB Video/500GB Western Dig. HD/Dark Basic Pro 7.4

No one cares how much you know until they know how much you care.
Unseen Ghost
22
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 21st Feb 2018 18:15
Ok,

I have one question that might be stupid, but if I don't know or not sure I as. How else am I suppose to learn.

The declaring of the array go outside the main loop and calling the stuff goes inside right?
Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 9400 GT(PNY)1GB Video/500GB Western Dig. HD/Dark Basic Pro 7.4

No one cares how much you know until they know how much you care.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 21st Feb 2018 19:28
yes declaring (and maybe the initial setup such as a basic rota) will go before the main loop
any code to allow users to change it will go in the loop as it will need to be checked in real time (such as functions)

so using Phaelax's example it could look something like this

life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Unseen Ghost
22
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 24th Feb 2018 17:30
I managed to get two of the functions working you provided smallg. I got the rotateforward and rotatebackwards to work with the virtual buttons. I had to make some minor code changes to the button release if statements. Instead of elseif I needed endif



Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 9400 GT(PNY)1GB Video/500GB Western Dig. HD/Dark Basic Pro 7.4

No one cares how much you know until they know how much you care.

Login to post a reply

Server time is: 2024-11-24 09:13:38
Your offset time is: 2024-11-24 09:13:38