Independent value on spawn?
So, on a very basic level, I have actors that are being ""Spawned"" on screen (I put that in quotations because it might be important to note that they actually aren't being physically spawned, they are all there on screen when the game scene begins, but then appear at different times by interpolating the color.alpha value in them to 1), they are all the same actor, but they each have a number assigned to them relating to a money system (irrelevant to this question), in an attribute called self.num, so like 1, 2, 3, all the up to 10 and beyond. Up till now ive been going into each actor and setting what each attributes value is manually, but for gameplay reasons, I thought it might be better to make the values different each time the scene is loaded. So how would I do this? How would I make it so that when the scene starts, they all pick a number from 1-X (x being modifiable as there are varying numbers of these things on each scene I make), but they never have the same number...
EDIT: Oh I should also say just in case this didnt come across that there can't be any skipped numbers. So if there are 10 of these actors, then they should have a number 1 through 10.
Comments
Are these actors in random positions ?
No, In each scene I have dragged copies of these actors to various positions on the screen, but that doesnt change within the scene. I just want to make the value that each of them has different.
@Flyboy12
Gotta love tables. #spoilers
Make a table.
Give the table as many rows as you have spawned actors. Say you have 10.
Make as many columus as you want. You will be randomly filling these out later.
Make an integer attribute called "randomizer"
Make a rule that says, when scene starts change attribute, "randomizer" to random(1, "Your maximum number of columns.")
Tell each individual actor that it should assign itself to a tablecellvalue(randomtable,1,"randomizer").
So if you have 10 actors
Actor 1 should change self.num to tablecellvalue(randomtable,1,"randomizer")
Actor 2 should change self.num to tablecellvalue(randomtable,2,"randomizer")
Actor 3 should change self.num to tablecellvalue(randomtable,3,"randomizer")
Actor 4 should change self.num to tablecellvalue(randomtable,4,"randomizer")
Actor 5 should change self.num to tablecellvalue(randomtable,5,"randomizer")
Actor 6 should change self.num to tablecellvalue(randomtable,6,"randomizer")
Actor 7 should change self.num to tablecellvalue(randomtable,7,"randomizer")
Actor 8 should change self.num to tablecellvalue(randomtable,8,"randomizer")
Actor 9 should change self.num to tablecellvalue(randomtable,9,"randomizer")
Actor 10 should change self.num to tablecellvalue(randomtable,10,"randomizer")
Each time the scene starts it will change the randomizer value. This will assign the actor to a random column every time.
You can fill out each column by just counting 1-10 and picking a space at random.
Wouldnt that cause duplicates? So I could have 2 actors that end up with 5, or 6 or whatever.
Plus, this method still requires me to go in and physically change each actors attributes. How could I set this up so I can just drag the actor on to the scene and its already going to pick a random number. (id probably have to enter in how many are there total for the scene but that's A OK)
I dont know a whole lot about tables, but couldnt you do something along the lines of removing rows or something? And then resetting when fail or win happens?
Here's a demo that picks a random number from a table. You can assign the number (game.randomNum) to a spawned actor by spawning the actor right after game.randomNum is given a value. In the spawned actor, Change Attribute self.myNum to game.randomNum (this should be outside of any rules and at the top of the actor's rule list).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@FlyboyTrevy_
It wouldn't cause duplicates if in each column you have numbers 1-10. No duplicate numbers.
Does your prototype actor have a self.num value? Yes you would have to literally change the self.num value. But if you have your rules set up to use the self.num value you should be ok.
Edited:You can fill out each column by just counting 1-10 and picking a space at random. no duplicate numbers.
I made a game where a laser would be assigned a number as it spawned. But the lasers had to be spawned at different times so their idetification number didn't overlap.
@tatiang The demo doesn't exactly solve anything for this thing here, at least as I understand it.
Each actor (chosen) has its own MyNum to start with, and this number never ends up chaning at all. Various things happen that cause these actors to appear at different times, which that part, in my own game, has nothing to do with this numbers thing. I just illustrated that to show that all the actors are in the scene to begin with, and are not added through a spawning system.
My goal here, is so that all the invisible actors (preferrably within 0.2 seconds) pick a number between 1 and however many actors there are, and there is no overlap. So that each actors self.mynum is different everytime. Because I have hundreds of rules and behaviors attatched to that mynum. Get it?
Sorry, I may not have read through this enough to give you a useful demo... Okay, so placed actors need to choose random unique numbers. Got it. Let me see what I can do.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Haha don't sweat it too much, I don't always explain things perfectly. Really appreciate it man
How's this?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Just a quick question, in the actor, there's the Add/remove row behavior, but it says "No editable tables in this project."
But the demo works just fine. What's supposed to be in here?
Here's the behavior:
The table is just a twenty row table with a single column of integers from 1 to 20.
I made the demo with Mac Creator 13.7 if it makes a difference. I downloaded the attachment above and it worked fine without any error messages.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Yeah the demo worked just fine everybody got a number and it didnt look like there were any repeats, but that was there. I'll just fill this in.
So, I applied this in my own program, and discovered that if a scene is reset (you click on the scene box on the scene selection at the bottom of the prototyping window or have a rule that resets the scene), every actor is zero.
Yep. The demo deletes table rows to ensure that no value is repeated. So if you reset the scene, you need to replace the table values. The best way to do this is to copy the table when the scene starts and then right before the scene resets, copy the backup to the "working" table used in your rules.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok, so when I replicated the demo into my program, it doesnt look like it's different every time. On the left is the my assign order number, and on the right is the mynum that it always ends up being.
1 - 1
2 - 2
3 - 0
4 - 3
Im going back and forth drying to find any dissonance between the two programs, but I can't seem to find any. Have any ideas on what I might have forgotten?
Not without seeing it.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
One of my timers was every instead of after. But that didnt seem to affect anything. Ill keep looking
The only other discrepancy I can seem to find is on the Game attributes tab, theres a "playerType" attribute, its an enumeration, and it has a blank dropdown menu, and under the blank selection in the dropdown, theres "error".
Does this have to do with just pro membership stuff, and nothing to do at all with this program?
Yes, that is for multiplayer networking and it shouldn't matter in the least if it's blank.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok, so I had a -1 where there should have been a +1
But im still getting zeroes for actors with assign order 1 and 2.
So for example, the actors (which all of them are not unlocked, they are all following the source and not their own instance) with assign orders 3, 4, and 5, could have any number between 1-5, so they could be 2, 5, and 1, or 4, 3, and 2. Or whatever. But theres always two numbers out of the 1-5 missing and replaced by zeroes in any actor with assign order 1 or 2.
This also happens if I change the assign orders around, any actor with a 1 or a 2 for their order gets zeroes. Hope that makes sense...
It makes sense but it's a bit like fumbling in the dark for me to not be able to see your rules and/or project file. I have no way of guessing what you did wrong. The demo I posted works so if you're having different results it means you implemented it incorrectly. It may be a simple fix or not, but again I'm not sure.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
No I totally understand. I'm just throwing it out there in case you might have recognized this before or knew exactly why this was the case, but I don't expect you to. I'm working on this again now, and I'll keep looking, if I still cant find anything Ill strip the game down to just this and throw it over to you.
Well... I have no idea what I changed, I tried something again that I had tried earlier, and it just decided to work now. Not complaining at all.
Now I just gotta work on implementing this into the money system, and it should work like a charm. Figuring this out would have probably taken me upwards of a month, so thanks Tatiang. Ill get back here if I notice anything else, but it should work fine.
So to go back to that table copy thing, I have the copy table behavior, so that when the scene starts, it copies the table to just a table I created called reserve. Then after about 2-3 seconds (long after all the numbers have been selected) I have the copy behavior again, but this time its copying reserve back to |T| Values. But later when the scene resets, im getting zeroes???? Any idea why? What am I doing wrong here.
No, I don't have any guesses, sorry.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Do you think it would be because all the rows are being removed and its being cleared out before it can be copied?
Is there any way to monitor a table during gametime?