Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, Yandex, DotBot

Members: 0
Guests: 16
Stats
Files
Topics
Posts
Members
Newest Member
481
3,735
19,370
618
Micheal64X
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » Coding » Hello again folks
Forum Rules | Mark all | Recent Posts

Hello again folks
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Aug 11, 2009, 3:30 pm
Go to the top of the page
Go to the bottom of the page

Sanus Compleo
Magician
GroupMembers
Posts153
JoinedMar 25, 2008

I've got a similar question to the ones I've asked in the past. Though I dunno if anyone remembers them. Anyway, the thing is, I need to pause a function until a certain parameter is met, but I have no idea how to do that. I tried a for( ) and a while( ) loop, but both of these generally wind up stopping the entire mud, so the condition never changes, and thus an infinite loop of freezing occurs. Oi. My question is, how can I pause *just* a function?
       
Post is unread #2 Aug 11, 2009, 3:41 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,873
JoinedJul 26, 2005

Chances are you have it looping. When you make a function like that what you do is first deal with it running once in awhile like all the other things in the mud are. You also have to make it so it only goes through the function when it needs to. Take a look at quest_update in update.c is where it's called, but it's all handled in quest.c quest_update.
       
Post is unread #3 Aug 11, 2009, 4:05 pm
Go to the top of the page
Go to the bottom of the page

Sanus Compleo
Magician
GroupMembers
Posts153
JoinedMar 25, 2008

Hrm.. I didn't think that the function being called would have been a problem. The loop was something like

while( condition <= 0 )
continue;

and just left it like that. I'm again not really sure how to keep it from going, and... I think it... no... Honestly I have no clue what I need to do. I feel utterly helpless >.>


The loop was in the mprog_driver, again still working on the easy version of mpsleep, hopefully one that would work, but it's been a couple of months, and I'm still no closer to getting it working.
       
Post is unread #4 Aug 11, 2009, 5:36 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,873
JoinedJul 26, 2005

Well in a while loop like that eventually you have to have condition > 0 to break out of it otherwise it will just continue going in an infinite loop.
       
Post is unread #5 Aug 11, 2009, 5:57 pm
Go to the top of the page
Go to the bottom of the page

Sanus Compleo
Magician
GroupMembers
Posts153
JoinedMar 25, 2008

Yeah, the condition that's supposed to decline (mob->sleep) goes down during char_update, which is in an entirely different file, much less function, and when the mprog_driver gets paused, everything quits working.
       
Post is unread #6 Aug 11, 2009, 7:04 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,873
JoinedJul 26, 2005

Well this is what your talking about (I think)
function( )
{
   while( condition <= 0 )
      continue;
}

function( )
{
   condition--;
}

That will never work inside the while loop condition would have to be increasing till its above 0. Hope that makes sense since i just used your example lol.
       
Post is unread #7 Aug 11, 2009, 7:09 pm
Go to the top of the page
Go to the bottom of the page

Sanus Compleo
Magician
GroupMembers
Posts153
JoinedMar 25, 2008

Oh, I think I had something backwards in the example. The sleep starts at... a number like... 5, or so, then goes down (hopefully every combat round, or every second) and I want the other function to... essentially, do nothing until sleep hits 0, or -1.
       
Post is unread #8 Aug 11, 2009, 7:32 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,873
JoinedJul 26, 2005

While it is in a while loop it will stay in the loop until the condition that keeps it there is no longer valid. If you only want it to run once a number hits 0 then you never do anything until it gets to 0 then do what you want and leave the function sort of like this
function( )
{
   if( condition > 0 )
      return;
   /* Else condition is 0 or lower so do what you need to do */
   does something
   /* Now set condition back up higher so it doesn't run this again for awhile */
   condition = 5;
}

Hope that helps :)
       
Post is unread #9 Aug 11, 2009, 8:12 pm   Last edited Aug 11, 2009, 8:15 pm by Sanus Compleo
Go to the top of the page
Go to the bottom of the page

Sanus Compleo
Magician
GroupMembers
Posts153
JoinedMar 25, 2008

I don't quite want it to return to the beginning of the function, unless there's something in mprog_driver that calls another function to interperate each line, and has it in a for statement or something, then I could go to that function and add the condition thing in there, but I dunno how I could have it specifically target the different things (mobs, objs, rooms) so that it waits until it's needed to. But there's also a problem with that, because there's no way to make it continue once the condition does work... Bah.
       
Post is unread #10 Aug 11, 2009, 9:57 pm
Go to the top of the page
Go to the bottom of the page

Tonitrus
Fledgling
GroupMembers
Posts47
JoinedJun 24, 2009

If you're trying this for smaug, you might want to look into smaug timers. You can defer a command by however much time you want, and then check the status of things at that time. It also can have a variety of different states. I don't recall the details on how to use them, nor do I know any decent documentation for them, I usually just find a function that uses them and hack it into what I want. The search skill uses them, I think.

But from what you described, which I didn't read as closely as I might have, I think you could probably put a timer on a mob and have it call a function that checks your other variable and then acts. And if the condition isn't set, you can always just have the timer reset itself. I believe you can have timers that call functions while other actions are going through, but I'm not 100% sure on that point. It might interupt when people/mobs enter commands, which would be entirely useless to you.

If that turns out to be the case, though, you could also cheat and make an affect to do it. When AFF_WTFEVER expires, call X function.

And while the timer or affect is in place, the mob/player does nothing (or whatever you define, really)
       
Pages:<< prev 1 next >>