Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Fat Pug Studio on November 11, 2017, 12:57:52 AM

Title: Ideas for system improvement
Post by: Fat Pug Studio on November 11, 2017, 12:57:52 AM
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:

PulseGunWeaponLevel1
PulseGunWeaponLevel2
PulseGunWeaponLevel3
PulseGunWeaponLevel4
PulseGunWeaponLevel5

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
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 http://hutonggames.com/playmakerforum/index.php?topic=16064.msg74988#msg74988 (http://hutonggames.com/playmakerforum/index.php?topic=16064.msg74988#msg74988), 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?
Title: Re: Ideas for system improvement
Post by: djaydino on November 11, 2017, 01:39:50 PM
Hi,
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) :)
Title: Re: Ideas for system improvement
Post by: Fat Pug Studio on November 11, 2017, 02:37:20 PM
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.
Title: Re: Ideas for system improvement
Post by: Fat Pug Studio on November 11, 2017, 02:48:39 PM
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 :)
Title: Re: Ideas for system improvement
Post by: djaydino on November 12, 2017, 07:40:18 AM
Hi,
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.

(https://i.imgur.com/GJi1Wol.png)

(https://i.imgur.com/XKrj6Y9.png)

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)
Title: Re: Ideas for system improvement
Post by: Fat Pug Studio on November 15, 2017, 08:34:44 AM
Great idea, i'll try it out! Thanks!