I'll quietly back away from the scary maths but thank you very much for all your help.
tatiangMember, Sous Chef, PRO, Senior Sous-ChefPosts: 11,949
edited May 2018
I know it looks intimidating.
textSubStr() is a function that returns a portion of a string (aka text attribute) from the character position of the first value to the character position of the second value. So textSubStr(turkey,4,6)="key".
In this case, I'm using a two-digit value that's part of a text attribute. The attribute example I gave was 05081119, which is 05 and 08 and 11 and 19 all strung together. I'm using two digits because if I did 581119, it would be hard to figure out mathematically what the third value (11) was. With two digits, level one is always represented in digits 1 & 2, level two in digits 3 & 4, level three in digits 5 & 6, etc. So to find the substring for any particular level, we need to know where it starts and ends:
Let's look at level 2. It's value starts at the third character and ends at the fourth:
05081119
^^
So mathematically if level=2 then the substring we want is between level * 2 - 1 (which would be 2 * 2 - 1 = 3) and level*2 (which equals 2 * 2 = 4). For any level, then, we can find the start and end of the substring by multiplying by 2 and subtracting one and then separately just multiplying by 2.
Chances are I haven't made this more clear for you. But I'm a teacher by profession so darn it, I had to try!
Here is a sample of an alternate approach. I'm not sure it's any better or less complex but it might be worth considering. Instead of putting each of your game screens in their own scene, I have created one large scene that holds both screens. This way you don't have to keep track of the coins to spawn/de-spawn since they are all in the same scene. This sample only used two game screens so you'd have to make an even larger scene to hold more. A drawback to this method will be that the more game screens you have the larger the scene will be and the more time it will take to load on the device.
But it's just a thought as an alternate way to solve your problem. I've placed a NOTE in the player actor explaining in more detail how it's working.
@highground said:
Thanks Tatiang,
I haven't ventured into creating tables yet so this is new ground....
Can I just check I've got this right:
We create 2x new attributes
self.SpawnID (for the coin actor)
game.SpawnID (game level attribute)
_------
We spawn multiple coins from a Spawner actor:
_------ Spawner actor
Change attribute game.spawnID to game.spawnID+1
When tableCellValue(tableName, game.spawnID, 1) = 0
Spawn actor [actor name]
_------
(this checks a table to see if it is 1 or 0)
_------
And in the Coin actor we add this rule.....
_------ Spawned actor
Change attribute self.spawnID to game.spawnID
When [actor needs to be destroyed]
Change Table Cell Value row: self.spawnID col: 1 value: 1
Destroy actor
_------
(this changes the coin's self.spawnID into the game.spawnID)
(and also has the rule to change the table cell value to 1 when we want to destroy the coin)
_------
Have I got that right??
If so, the only thing I don't understand is how to set up the table to be populated with these details.
Could you just go over that bit and I think I'll have it
(go slowly as if I'm an idiot!)
_------
How do you put that in...what condition or behavior?
Comments
Hi Tatiang,
thanks for this.
I'm afraid I'm just learning the ropes and this part.....
textSubStr(game.coinsToSpawn, game.level * 2 -1, game.level * 2)
is way beyond my understanding.
I'll quietly back away from the scary maths but thank you very much for all your help.
I know it looks intimidating.
textSubStr() is a function that returns a portion of a string (aka text attribute) from the character position of the first value to the character position of the second value. So textSubStr(turkey,4,6)="key".
In this case, I'm using a two-digit value that's part of a text attribute. The attribute example I gave was 05081119, which is 05 and 08 and 11 and 19 all strung together. I'm using two digits because if I did 581119, it would be hard to figure out mathematically what the third value (11) was. With two digits, level one is always represented in digits 1 & 2, level two in digits 3 & 4, level three in digits 5 & 6, etc. So to find the substring for any particular level, we need to know where it starts and ends:
Let's look at level 2. It's value starts at the third character and ends at the fourth:
05081119
^^
So mathematically if level=2 then the substring we want is between level * 2 - 1 (which would be 2 * 2 - 1 = 3) and level*2 (which equals 2 * 2 = 4). For any level, then, we can find the start and end of the substring by multiplying by 2 and subtracting one and then separately just multiplying by 2.
Chances are I haven't made this more clear for you. But I'm a teacher by profession so darn it, I had to try!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Here is a sample of an alternate approach. I'm not sure it's any better or less complex but it might be worth considering. Instead of putting each of your game screens in their own scene, I have created one large scene that holds both screens. This way you don't have to keep track of the coins to spawn/de-spawn since they are all in the same scene. This sample only used two game screens so you'd have to make an even larger scene to hold more. A drawback to this method will be that the more game screens you have the larger the scene will be and the more time it will take to load on the device.
But it's just a thought as an alternate way to solve your problem. I've placed a NOTE in the player actor explaining in more detail how it's working.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
How do you put that in...what condition or behavior?