will
Newish
Posts: 28
|
Post by will on Jul 24, 2009 10:13:29 GMT -5
struc Item dim Name$ dim NamePref$ dim NameSuf$ dim Att dim Def dim Vit dim Man dim Mny endstruc
Wood.Name$ = "Wood" Wood.NamePref$ = "Foresters" Wood.Att = 1 Wood.Def = 0 Wood.Vit = 0 Wood.Man = 0 Wood.Mny = 4
'lotsa code
sub ApplyStats(ItemName$) WepAtt = WepAtt + ItemName$.Att WepDef = WepDef + ItemName$.Def WepVit = WepVit + ItemName$.Vit WepMan = WepMan + ItemName$.Man WepVal = WepVal + ItemName$.Mny end sub
'some more code
if hilttype = 2 then print Wood.NamePref$ + " " ApplyStats(Wood.Name$) endif
What i am trying to make it do is have a subroutine that i can pass any such item name to. So, even if the item name was "Bananaboat" it would still add up all the stats of "Bananaboat", just as it would do with "Wood". For some reason the above code doesn't work, i have tried many things with no luck. Any help is appreciated.
|
|
|
Post by xteraco on Jul 29, 2009 11:02:31 GMT -5
The answer to your problems here is functions. Subs do not accept arguments or return values. Here is a simple example I wrote of how to use functions to pass around data.
struc car dim speed dim damage dim horsepower endstruc
function accelerate(power) dim windresistance : windresistance = 2 return power - windresistance end function
function applyDamage(speed) return speed * 3 end function
'accelerate our care dim honda as car honda.horsepower = 10
printr "before functions" printr "speed = " + honda.speed printr "damage = " + honda.damage
honda.speed = accelerate( honda.horsepower ) honda.damage = applyDamage( honda.speed )
sleep(5000) cls printr "after functions" printr "speed = " + honda.speed printr "damage = " + honda.damage
As you can see the function takes an argument and makes a calculation based on the data coming in. When the calculation is complete it returns a new value. This new value is assigned to your variable.
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Jul 29, 2009 12:25:39 GMT -5
Double standards much, xteraco?
|
|
|
Post by xteraco on Jul 29, 2009 12:55:50 GMT -5
You're silly OW. hehe
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Jul 29, 2009 13:06:10 GMT -5
You're a hypocrite xteraco. hehe
|
|