Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
albo
Apprentice


Joined: 27 Mar 2008
Posts: 103

PostPosted: Thu Jun 11, 2020 6:04 pm   

Can you call functions from within functions?
 
Hi there,

I have a function that I was using the #SWITCH command in at first, because I have several things I'm trying to evaluate for a true or false status. I'd like to call a function if one of the cases in the switch statement evaluate to true, but after some testing and debugging the function nested in my function is not being called. I then changed the switch statement to be nested if statements, but that is not working either.


Code:
#IF (@unrefinedIron = 5) {@smeltTheOre(Iron)} {#IF (@unrefinedTitanium = 5) {@smeltTheOre(Titanium)} {#IF (@unrefinedCopper = 5) {@smeltTheOre(Copper)} {#IF (@unrefinedGold = 5) {@smeltTheOre(Gold)} {#IF (@unrefinedSilver = 5) {@smeltTheOre(Silver)} {#IF (@unrefinedPlatinum = 5) {@smeltTheOre(Platinum)} {get unrefined kaka}}}}}}


The above is my code for the first function being called, that has the nested function. The below is the code for the nested function.
Code:

smelt $a unrefined
#IF ($a = Iron) {@unrefinedIron = 0}
#IF ($a = Copper) {@unrefinedCopper = 0}
#IF ($a = Gold) {@unrefinedGold = 0}
#IF ($a = Platinum) {@unrefinedPlatinum = 0}
#IF ($a = Silver) {@unrefinedSilver = 0}
#IF ($a = Titanium) {@unrefinedTitanium = 0}


I'm not sure why my function smeltTheOre() is not being called.
Reply with quote
unrealtor
Newbie


Joined: 23 May 2020
Posts: 6

PostPosted: Thu Jun 11, 2020 10:52 pm   
 
// formatting the code to check syntax and seems fine
#IF (@unrefinedIron = 5) {@smeltTheOre(Iron)} {
#IF (@unrefinedTitanium = 5) {@smeltTheOre(Titanium)} {
#IF (@unrefinedCopper = 5) {@smeltTheOre(Copper)} {
#IF (@unrefinedGold = 5) {@smeltTheOre(Gold)} {
#IF (@unrefinedSilver = 5) {@smeltTheOre(Silver)} {
#IF (@unrefinedPlatinum = 5) {@smeltTheOre(Platinum)} {
get unrefined kaka
}
}
}
}
}
}

Could it be that you are comparing a string to an integer? Try as follows:
#IF (%int(@unrefinedIron) = 5) {@smeltTheOre(Iron)}
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4190
Location: Pensacola, FL, USA

PostPosted: Fri Jun 12, 2020 12:21 am   
 
Yes, you can, however, #FUNCTIONs only return a value, you are trying to use it as an #ALIAS.

That aside, given the way you structured this, you can make good use of %concat and skip a lot of code:

#IF (%int(%concat("@unrefined", $a)) = 5) {smelt $a unrefined;#VAR %concat("unrefined", $a) {0}} {get unrefined kaka}
_________________
Discord: Shalimar#3679
Reply with quote
albo
Apprentice


Joined: 27 Mar 2008
Posts: 103

PostPosted: Sun Jun 14, 2020 4:47 pm   
 
Thank you both for taking a look at that! I worked it out by using more code and breaking out the functions, but I really like the solution provided shalimar. Now I've got to craft a bunch of items, so I'll probably take the advice of using %concat and apply it to crafting items from all the smelted ore. When my character in the MUD grabs a piece of ore from a container I can either specify the quality or the type, but not both. These means I have to track the quality and the type and when crafting I need to have a certain amount of a specific type and quality. I should be able to reduce the amount of code I use with the %concat function.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net