ID:828005
 
Keywords: datums
(See the best response by Pirion.)
I must be really really slow as I keep reading about them and don't get them at all. So Datums are ancestors to everything right? And they store data? But I don't get how to use them or how to make my coding simpler with them.

I think I did this right:

randomdmg
var
randdmg
proc
rdmg()
randdmg=rand(1,10)
world << "[randdmg] damage!"

mob/var/randomdmg/rdmgtwo

mob/proc/randatk()
rdmgtwo.rdmg()


I am trying to make a verb based on that but nothing works. I just don't know what to do with this! How do I use this to make my coding simpler?

I have this for example:

    proc
battleinput()
while(1) //while 1 is true which is always
if(src.loc==locate(12,6,1) | src.loc==locate(12,3,1) | src.loc==locate(11,9,1) && src.pturn) //if the location of myself and my 2 allies is true as well as if its my turn. pturn means player's turn.
for(var/mob/enemy/Prowler/o in locate(15,6,1)) //defining enemy 1: Prowler that already exists in location 15,6,1 of my map
for(var/mob/enemy/Bandit/i in locate(15,3,1))
world << "[src]'s turn" //who's turn
var/tmp/action=input("What would you like to do?") in list ("Attack", "Run") // input turn actions. variable is "action"
if(action=="Attack") //if that action is attack
var/tmp/attackwho=input("Attack who?") in list ("Enemy 1", "Enemy 2") // second input this time choosing to attack who. variable is "attackwho"
if(attackwho=="Enemy 1")//if chosen enemy 1
var/tmp/randomdmg = rand(1,10) // random damamge variable
o.hp-= randomdmg //"o" Prowler variable is damaged randomly
world << "[src] attacks [o] for [randomdmg] dmg" //outputs into the world what has happened. the player attacked prowler for that random damage
src.pturn=0 // player's turn becomes 0 so its not my turn anyore
cancel3rd4=1
cancel2nd4=1
if(attackwho=="Enemy 2") //same as above just enemy 2
var/tmp/randomdmg = rand(1,30)
i.hp-=randomdmg
world << "[src] attacks [i] for [randomdmg] dmg"
src.pturn=0
cancel3rd4=1
cancel2nd4=1
if(action=="Run") // if chose the action Run
if(prob(20)) // 20% probability to run away
src.loc=prevloc // returns to previous location as I defined it in the Move() proc
src.pturn=1 //returns player's turn to 0 if run away
else src.pturn=0 // if I don't run away then its no longer my turn
// global turn 2 making it Prowler's turn
sleep(10)


How can a Datum make this simpler and shorter?
Best response
TheDarkChakra wrote:
I must be really really slow as I keep reading about them and don't get them at all. So Datums are ancestors to everything right? And they store data? But I don't get how to use them or how to make my coding simpler with them.

I think I did this right:

randomdmg
> var
> randdmg
> proc
> rdmg()
> randdmg=rand(1,10)
> world << "[randdmg] damage!"
>
> mob/var/randomdmg/rdmgtwo
>
> mob/proc/randatk()
> rdmgtwo.rdmg()

I am trying to make a verb based on that but nothing works. I just don't know what to do with this!

So looking at this piece, the thing that was missed was to initialize a new instance of the rdmgtwo.

> mob/var/randomdmg/rdmgtwo = new()


Then anytime you need this, you can call src.rdmgtwo.rdmg() where src is the mob that owns this.

You can also define it in the global scope (with just putting var/randomdmg/rdmgtwo = new()) as it does a function that may not be specific to just that one mob.

Now for the battle, to make the simpler my datum would look like this:

encounter
{
var
{
list/teams = new() //this tells us who is fighting.
}

proc
{
EncounterMain()
{
while(NoWinner())
{
var/list/TurnOrder = GetTurnOrder() //Get list of people and their turn order. Also include their speed incase something changes with a skill.
var/list/BattleSelections = GetBattleSelections()//Select the actions at the beginning of the turn.
MakeActions(TurnOrder,BattleSelections)//Do the actions prevously selected, by the order previously decided.
StatusEffects()//Hurt based on statuses, and check if they are gone now.
}
}


NoWinner() //The Extracted logic of is match over.
{
for(var/Team/x in teams)
{
var/count
if(x.LivingMembers())
{
count++
}
if(count>=2)
{
return TRUE;
}
else
{
return FALSE;
}
}
}
}

}


I only coded one of the items in it as it would be pretty long for a system like this, but it is much more flexible that what you have here.

Your system is built to ALWAYs have only 1 player and always be 2 enemies. Although you can shorten yours greatly, there is not really much going on.
So looking at this piece, the thing that was missed was to >initialize a new instance of the rdmgtwo.
mob/var/randomdmg/rdmgtwo = new()

So THAT is what was missing! Now it works. Thank you.