Playmaker Help & Tips > Playmaker Help

Ideas for system improvement

(1/2) > >>

Hi guys,

I remade the weapon, firing, bullet and pickup system into something more universal, so i can just copy/paste FSM's to necessary objects and use local variables to do the necessary stuff, but there's an oversight i made and i need a fix. Here's a quick explanation.

I have weapons which names are structured like this:


Since i'm using pooling system, (clone 1), (clone 2) etc. string is appended when the weapon is spawned, so the name are actually like this:

PulseGunWeaponLevel1 (clone 1)
PulseGunWeaponLevel2 (clone 1)
PulseGunWeaponLevel3 (clone 1)
PulseGunWeaponLevel4 (clone 1)
PulseGunWeaponLevel5 (clone 1)

Since there will be no more than a few instances in the scene (certainly not more than nine) it made sense to make the folowing hash tables:

PlayerWeapon Key / PlayerWeapon Value
PulseGunLevel1 (string)/PulseGunLevel 1 (object)

To get the true object name out of a spawned object which contains (clone x) appendix, i get the object name, get name length, convert it into string, use the int operator to subtract the last 10 characters (" (clone_1)"), and the get string left to get the name without the (clone 1) appendix. Then i can use that name to get whatever data i need on that weapon on runtime (display name, weapon type display name for the hud and so on).

While not so complicated and applicable to weapons, it is not applicable to bullets since they appear in more than nine instances (clone 10, for example) on the screen and the whole "subtract last 10 characters" idea falls flat. Sure, i could compare the string length and then subtract last 10 or 11 characters depending on the length, but it it unnecessary complicated.

Djaydino had some ideas, and he was pointing to the problem in time, but i'm not sure how to do it, so any suggestions or step-by-steps are welcome.

Maybe using enums? I haven't used them before though. Can i define an enum so that every pooled clone always has the same name actually so i don't have to mess around with string concatenation, building and truncating?

I still think the easiest way is to place an fsm on the items and just have some variables (no actions needed)

And on pickup get the variables (weapon name / weapon type / any other info needed) you can even feed the data to the weapon from an xml and there is no problem with (clone) :)

You mean when i pick it up, the weapon equipped on ship gets fsm variables from the pickup like name, other components and so on? I don't think it's a bad idea, i just don't have an idea how to handle the upgrade mechanics other then comparing the name of the pickup.

Would i get into a problem if i rename the clones to their original names on spawn? Can two same named object exist in the same scene at all anyway?

Edit: i just read that they can, i just need to check if there will be trouble on despawning.

I'm using Pool Boss for pooling and just read the API, there's a getprefabname method that will solve all the string stuff, but i think it can still be much more elegant and not string dependant :)

When are you getting the object name?
Instead of getting the true object name and cut the (clone) from it try this:

Have a variable on the object (call it 'WeaponNameValue' or something, just be sure to use the same variable name on all objects)
and set the weapon name in that variable Value (PulseGunWeaponLevel1, PulseGunWeaponLevel2, ...)

Then on the FSM/State where you are getting the 'true name' remove it and use "Get fsm string"
In the 'Variable Name' set 'WeaponNameValue' as value.

Then store the value and continue to your next states/actions.

You could use int values instead of a string and use 'get fsm int' to identify the weapons (item Id's are used in minecraft for example and many other games)


[0] Message Index

[#] Next page

Go to full version