The Daily Click ::. Forums ::. Klik Coding Help ::. Spread Value problem
 

Post Reply  Post Oekaki 
 

Posted By Message

OMC

What a goofball

Registered
  21/05/2007
Points
  3539

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
8th June, 2010 at 18:27:11 -

You probably don't need a loop for that. You never know though. What movement are you using? Is it built-in or custom?

Edited by OMC

 

  		
  		

MBK



Registered
  07/06/2007
Points
  1578

VIP Member
9th June, 2010 at 06:01:25 -


How does Modulus work? .. Is that the thing that finds a remainder? .. How would that work?

I'm thinking you could devide the Alt Value by 2 and if that value's remainder is zero, make the enemy look left, but if that value's remainder is not zero, make the enemy look right.

But yea ... does Mod work like that?
How exactly would that be written if so?


 
Click Me! http://www.create-games.com/project.asp?view=main&id=1444

http://www.mediafire.com/download.php?aoo1dnnlq5i

Blood of the Ancient One, Seen only as Shadow, Faster than Lightning, Fierce as the Greatest Dragon, Nearly Invisible, Floating in a Dream, Entered through the Demon Door, Destroyer of Evil in a Realm with a Red Sky Scarred, Who could I be ?

superpower



Registered
  07/06/2010
Points
  27
9th June, 2010 at 08:08:27 -

I don't think it'll work without loops since every enemy will turn, whereas I want there to be a random chance for some of them to do it. And yes, I'm using a custom built movement engine (that I totally nailed last night, booyah!). However MBK here may be on to something. Since values are individual, I could maybe do it like this:

- run event only once (I like failsafes)
+Start of frame
+2 chances out of 5 at random
--- Change Alterable Value "Initial Direction" to 1

- run event only once
+ When Alterable Value "Initial Direction" = 1
--- Change "Initial Direction" to 0
--- Change Alterable Value "Moving" to 1 (1 moves enemy right and -1 moves him left, I make them start of with -1 by default)

Can't wait to try it when I get home

 
n/a

superpower



Registered
  07/06/2010
Points
  27
9th June, 2010 at 17:01:17 -

I just tried out multiple enemies in the game and it seems I have this really weird bug. Depending on how high in the air I place them, in relation to each other, after falling down, they will either fall through the floor, stand still or run around (they should be running around). Nothing should be wrong with the movement engine itself, which leads me to believe that it's another spread value problem. I've tried both:

- Start of frame
--- Spread Value 0 in ID of "Enemy"
--- Spread Value 0 in ID of "Enemy Sprite"

- Always
--- Set position of "Enemy Sprite" at 0,0 from "Enemy"



and




- Always
--- Start loop "loop1" NObjects( "Enemy" ) times

- Start of frame
--- Spread value "0" in "ID" of "Enemy"
--- Spread value "0" in "ID" of "Enemy Sprite"

- On loop "Loop1"
+ ID of "Enemy" = Loopindex("Loop1")
+ Always
--- Set position of "Enemy Sprite" at 0,0 from "Enemy"



I've also tried flipping around and playing around with the "Start of frame" and "Always" functions just in case...
Any ideas!?

- Thanks again TDC!

Edited by superpower

 
n/a

superpower



Registered
  07/06/2010
Points
  27
10th June, 2010 at 13:02:43 -

I've actually solved that now. I just had a bunch of events in the wrong order
However, now there appears to be yet another problem

Since my sprite is a different object to the "enemy" object itself I have used these spread value events:

- Start of frame
--- Spread value 0 in "ID" of "Enemy"
--- Spread value 0 in "ID" of "Enemy Sprite"

- Always
--- Set position of "Enemy Sprite" to "Enemy"
--- Set direction of "Enemy Sprite" to "Enemy"

But how can I make more complex things like changing between animations possible.
I now have it set up like this:

- Alterable value "Moving" of "Enemy" = 1
+ Alterable value "Falling" of "Enemy" = 0
--- Change "Enemy Sprite" animation to "walking"

And this doesn't work since MMF doesn't know which Enemy sprite needs to change it's animation sequence.

 
n/a

OMC

What a goofball

Registered
  21/05/2007
Points
  3539

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
10th June, 2010 at 15:22:03 -

Yes, separating objects can be a big pain in the patooter!

I might try sticking a condition at the top of that event: "ID" of enemy sprite = "ID" of enemy
Not sure if it will work but it might.

If it doesn't, a workaround should be put in place. Perhaps have a value box (an active placed outside of the frame that just hold values--I love those). Then do this:
- Alterable value "Moving" of "Enemy" = 1
+ Alterable value "Falling" of "Enemy" = 0
>> Change Value Box value "Enemy ID" to (animation number). (When you go to the change alterable value menu, hit "use expression" by the value selector. Then get the enemy's ID)

Always: Set enemy sprite animation to Value Box "Enemy ID". (Use Alterable value by index and get the Enemy ID here).

Or come up with something else creative!

 

  		
  		

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1969

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
10th June, 2010 at 16:35:53 -


Originally Posted by superpower
I've actually solved that now. I just had a bunch of events in the wrong order
However, now there appears to be yet another problem

Since my sprite is a different object to the "enemy" object itself I have used these spread value events:

- Start of frame
--- Spread value 0 in "ID" of "Enemy"
--- Spread value 0 in "ID" of "Enemy Sprite"

- Always
--- Set position of "Enemy Sprite" to "Enemy"
--- Set direction of "Enemy Sprite" to "Enemy"

But how can I make more complex things like changing between animations possible.
I now have it set up like this:

- Alterable value "Moving" of "Enemy" = 1
+ Alterable value "Falling" of "Enemy" = 0
--- Change "Enemy Sprite" animation to "walking"

And this doesn't work since MMF doesn't know which Enemy sprite needs to change it's animation sequence.



There's no point in spreading a value if you're not going to compare it later.
All "spread value" does is give each instance a different value (starting with the number you specify, which is allocated to the most recently created instance) - it doesn't magically pair objects up by itself.

Your first example would still have worked even without spreading a value, just because in this situation, MMF knows to pair objects according to the order in which they were created.
You could apply the same principle to your second example, using one of the "Enemy" object's alterable values to store the animation sequence of the corresponding "Enemy Sprite".

eg. Something like this:

- Alterable value "Moving" of "Enemy" = 1
+ Alterable value "Falling" of "Enemy" = 0
--- Set AnimSeq("Enemy") to 1

Always
--- Change animation sequence of "Enemy Sprite" to AnimSeq("Enemy")
(You need to click the "Use a calculation" button when selecting an animation sequence; 0=Stopped).

Alternatively, you could do it the way you have already tried, in which case you need to include the condition "If ID("Enemy Spite") = ID("Enemy") as OMC suggested.

 
n/a

superpower



Registered
  07/06/2010
Points
  27
10th June, 2010 at 17:26:01 -

I've tried the "If ID("Enemy Spite") = ID("Enemy")"-way, but it just doesn't work, and I just read an old article by Tigerworks that explained why it doesn't. This means that to me, spread values are pretty much useless (what a relief). But what amazes me the most is that your way, Sketchy, seems to work fine. Why it does, I don't know... I just added an extra alterable value called "animation" to the "Enemy" object and made it change it's value alongside the "moving" value. However, how the sprite knows which "enemy" objects value to use is frankly beyond me...!?

Could you please explain...!?

PS.
Something that would be seriously cool would be a way to spread value in global values. Now that I could use!

Edited by superpower

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1969

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
10th June, 2010 at 17:56:23 -

In that case, it must be:
"If ID("Enemy") = ID("Enemy Spite")"

instead of:
"If ID("Enemy Spite") = ID("Enemy")"

The two are not the same, and I get them mixed up sometimes.
I assure you, if you have everything ordered right (it also needs to be the first condition in the list), then it will work fine, and is actually the way I would recommend.

Re: The other method I described -
As long as you don't add any other conditions which would cause MMF to focus on a specifc instance (or instances), then it will always pair objects according to how recently they were created.
If you say: "Always position Object_A at 0,0 from Object_B", then each instance of Object_A will position itself over a different instance Object_B.
The newest instance of Object_A is paired with the newest instance of Object_B; the next-newest instance of Object_A is paired with the next-newest instance of Object_B; and so on...

I think this article by Pixelthief might kind of explain it:
http://www.create-games.com/article.asp?id=1942

Re: Spread <value> in Global Value -
How would that even work? There can only ever be one of each global value.
If you mean that you want to set GV_A to 0, GV_B to 1, GV_C to 2, etc - then it's quite easy, but I don't see how it would be useful.

- Whenever
--- Start Fastloop "SetGlobal", "26" times <-- or however many global values you want to change

- On loop "SetGlobal"
--- Set Global: LoopIndex("SetGlobal") to LoopIndex("SetGlobal") <-- you need to click the "Edit" button next to the list of global values.

Edited by Sketchy

 
n/a

superpower



Registered
  07/06/2010
Points
  27
11th June, 2010 at 07:54:13 -


Originally Posted by Sketchy
In that case, it must be:
"If ID("Enemy") = ID("Enemy Spite")"

instead of:
"If ID("Enemy Spite") = ID("Enemy")"

The two are not the same, and I get them mixed up sometimes.
I assure you, if you have everything ordered right (it also needs to be the first condition in the list), then it will work fine, and is actually the way I would recommend.

Re: The other method I described -
As long as you don't add any other conditions which would cause MMF to focus on a specifc instance (or instances), then it will always pair objects according to how recently they were created.
If you say: "Always position Object_A at 0,0 from Object_B", then each instance of Object_A will position itself over a different instance Object_B.
The newest instance of Object_A is paired with the newest instance of Object_B; the next-newest instance of Object_A is paired with the next-newest instance of Object_B; and so on...

I think this article by Pixelthief might kind of explain it:
http://www.create-games.com/article.asp?id=1942

Re: Spread <value> in Global Value -
How would that even work? There can only ever be one of each global value.
If you mean that you want to set GV_A to 0, GV_B to 1, GV_C to 2, etc - then it's quite easy, but I don't see how it would be useful.

- Whenever
--- Start Fastloop "SetGlobal", "26" times <-- or however many global values you want to change

- On loop "SetGlobal"
--- Set Global: LoopIndex("SetGlobal") to LoopIndex("SetGlobal") <-- you need to click the "Edit" button next to the list of global values.



Neither "If ID("Enemy") = ID("Enemy Spite")" nor "If ID("Enemy Sprite") = ID("Enemy")" works, they just fall through the platforms. I might just be doing something else wrong though. I haven't yet developed a decent understanding of spread values, as you probably noticed from my "if you could spread values in global values" post.
Darn it! I always think of spread values the wrong way and never learn
I always seem to think that first it spreads through an alterable value, sort of "applying" the number of numbers (yeah, you heard right) for later use by the objects. Even though that doesn't make any sense to any of you, trust me, after 3 days of constant work on an AI engine, it did to me

And just to clarify, "how recently the objects were created" means how recently they were created after the application has started, not after I duplicated them in the frame?
Does that basically mean that they are assigned some sort of "number value" and then pair up with their corresponding numbers of different objects?

Edited by superpower

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1969

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
11th June, 2010 at 09:29:41 -

"How recently they were created" applies whether the object was created at runtime or in the frame editor.
eg. Spreading "0" in four instances of an object:
3 - First instance created in frame editor,
2 - Duplicate created in frame editor,
1 - First object created at runtime,
0 - Second object created at runtime.

And yes, objects *are* assigned "some sort of number value" - it's contained within their "fixed value" (for objects created in the frame editor, it's basically the number that appears when you click on them).
http://www.create-games.com/article.asp?id=2139

 
n/a

superpower



Registered
  07/06/2010
Points
  27
11th June, 2010 at 09:49:25 -


Originally Posted by Sketchy
"How recently they were created" applies whether the object was created at runtime or in the frame editor.
eg. Spreading "0" in four instances of an object:
3 - First instance created in frame editor,
2 - Duplicate created in frame editor,
1 - First object created at runtime,
0 - Second object created at runtime.

And yes, objects *are* assigned "some sort of number value" - it's contained within their "fixed value" (for objects created in the frame editor, it's basically the number that appears when you click on them).
http://www.create-games.com/article.asp?id=2139

I'll might have to look into this later, but for now, I don't need it.
At a quick glance though, seems like a nice article...

 
n/a

superpower



Registered
  07/06/2010
Points
  27
11th June, 2010 at 13:46:56 -

How do I do a function like "If number of objects whose alterable value is X"?
or
"Set alterable value of "object 1" to number of "object 2" overlapping "object 1"?

I'm only now starting to realise how limited MMF really is.
For example why can't you make the zone in "test for number of objects in a zone" relative to a particular object!?

Edited by superpower

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1969

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
11th June, 2010 at 16:16:54 -

Testing for the number of objects in a zone is just meant to be a quick and easy feature to help beginners - much like the built-in movements / shooting etc. If you need more control, you can easily code it yourself.

eg.

+ Always
-> Set In_Zone("Object_A") to 0

+ X("Object_A") > X_Zone_Center - (Zone_Width / 2)
+ X("Object_A") < X_Zone_Center + (Zone_Width / 2)
+ Y("Object_A") > Y_Zone_Center - (Zone_Height / 2)
+ Y("Object_A") < Y_Zone_Center + (Zone_Height / 2)
-> Set In_Zone("Object_A") to 1


To count the number of objects whose value is X (or in this case, whose "In_Zone" = 1), there are two alternatives.
1.) The hard way, which is to fastloop through each instance of the object (by comparing a spread alterable value to the loop index), and individually check their alterable values.
2.) The super easy way, which is to simply use the "Select Object" extension

Edited by Sketchy

 
n/a

superpower



Registered
  07/06/2010
Points
  27
15th June, 2010 at 14:20:33 -

I'm having HUGE trouble with something that is essential in my upcoming game. I need enemies to move over if they're overlapping another enemy so that you can't kill them both with one punch. Everything I've tried has resulted in a complete failure. It doesn't matter what kind of movement engines and stuff you use. What fails for me is that if I do something like checking the position relative to another instance of the same enemy, it instead of using another instance as a comparison uses itself as the comparison. Bottom line: how would you do it!? I wan't to hear every suggestion from hitboxes to spread values (altough I've heard spread values are trouble when exporting to flash).

- Thanks TDC

 
n/a
   

Post Reply



 



Advertisement

Worth A Click