Ritualistic Forums

Go Back   Ritualistic Forums > Ritual Entertainment Games > SiN, SiN Steam & Wages of Sin

Reply
 
Thread Tools Display Modes
Old 05-22-1999, 04:41 AM   #1
claudec
Fanatic
 
Join Date: Feb 1999
Location: Chicago
Posts: 1,736
Default How do you do open thread and looping? I keep getting infinate loop error.

The scripting doc at at the node indicates you can do this -

mycool_thread:
<code for cool stuff>
goto mycool_thread
end

well it doesn't work for me I get an infinate loop error.
I have also tried -

mycool_thread:
loop_around:
<code for cool stuff>
goto loop_around
end

and that gets me the same error.
Below is some actual script I am working with.
the error I get is "Possible infinate loop in thread doexplosions_thread". Note the bit of funkyness I had to do in order to trick Sin into thinking fxmaster_thread was not an infinate loop. I tried similar things in doexplosions_thread and nothing worked. At one point changes made in doexplosion thread casued the error to occur for fxmaster_thread this is highly irratic.
How do I do loops that are the equlivant of FOR K = 1 to 3 DO
END;
and How do I do open threads?

I appreciate any help.

fxmaster_thread:
local.keepgoing = 1
fxmaster_begin:
local.do_explode randomint 500
local.do_explode ifequal 50 thread doexplosions_thread
local.keepgoing ifequal 1 goto fxmaster_begin
end
//end fxmaster_thread


doexplosions_thread:

local.explosion_number = 3
explosion_loop:

$explode1 activate


local.explosion_number -=1
local.explosion_number ifnotequal 0 goto explosion_loop

end
//end doexplosions_thread




------------------
claudec is offline   Reply With Quote
Old 05-22-1999, 09:19 AM   #2
eutectic
Fanboy
 
Join Date: Jan 1999
Posts: 844
Default Re: How do you do open thread and looping? I keep getting infinate loop error.

Ok, if I understand correctly, you want your thread to activate an explosion effect (probably a func_exploder) 3 times in a random fashion, right?

The reason why you get an infinite loop is very simple: timing.

1. The commands in a thread are executed very fast and at some point, you random number generating thread is probably calling the explosion effects thread while it's still running from the last time it was called. The trick is to make sure that only one instance of that thread can run at any given time.

2. Your explosions thread when it runs has no "wait" commands so the exploder entity is triggered 3 times in a row superfast without giving any delays between the explosions.

The wait and waitfor commands are very very important in threads because that's what controls the timing of events. This is often all that's needed to fix an infinite loop.

Also, when you write scripts, it's always best if you can to have all the code that relates to a single gadget in the map all in the same thread whenever possible. I tend to limit calling a thread from another thread to when there are good reasons to do this.

Another thing I noticed is that if you generate a random number between 0 and 499 (randomint 500), it's not going to fall on 50 too often. You could wait for a whole hour for this to occur. I suggest using something like 10 or 20 and let the explosions occur when the value is 5 for example.

So here's what I suggest for this:

thread fxmaster_thread
end

// That's how you call ("open") threads:
// with the thread command at the
// beginning of your script. Don't forget
// end command

fxmaster_thread:
local.do_explode randomint 10
wait 1
local.do_explode ifnotequal 5 goto fxmaster_thread

// Notice here how I introduce a wait command
// This is what prevents the infinite loop.
// Wait doesn't have to be 1 but at least
// something like 0.2 to give the script a
// chance to set the variable and compare.
// Also notice how I go back to the beginning
// if the number is NOT 5 instead of the opposite.
// If it IS 5, the thread can continue to
// the next command.

local.explosion_number = 3

explosion_loop:

trigger $explode1
wait 1
local.explosion_number -=1
local.explosion_number ifnotequal 0 goto explosion_loop
goto fxmaster_thread
end

// Notice here how I also introduced a wait
// between each explosion: very important.
// Also, I'm assuming you use a func_exploder
// here. You have to use the trigger command:
// activate doesn't work for this entity.

Of course, I tested this thread in a map and it works 100% as I always do before I post an answer. The rest is a matter of tweaking the random number value and wait times to suit your specific needs: how often you want the 3 explosions to occur and how much time between each.

So you see, doing a goto to the beginning of thread is entirely OK. It's all in the timing. The biggest advantage here is that all the code relating to the random explosions is confined to the same thread. There's no need to call another thread from the main one here.

So when you get infinite loops, always look for these kind of things when debugging threads and analyze the commands step by step. Remember that everything is executed REALLY fast unless you slow it down with wait or waitfor commands.

------------------
The Node
www.ritualistic.com/node

The official Sin entities and scripting reference site
eutectic is offline   Reply With Quote
Old 05-24-1999, 05:26 PM   #3
claudec
Fanatic
 
Join Date: Feb 1999
Location: Chicago
Posts: 1,736
Default Re: How do you do open thread and looping? I keep getting infinate loop error.

Thanks you helped me out a lot. I have done a lot more with the script since you posted your reply.
You are correct that it is generaly better to keep things that are logicaly related in one thread. The opposite is also true, keep things not related in seperate threads. I decided to keep it threaded as there are a few different FX sequences called by fxmaster_thread. I think I should have explained it better. fxmaster_thread is an open thread. It chooses at random which FX sequence to run it can also decide to do nothing. The FX sequences can be involved enough to warrent keeping them logicaly seperated. I have it set up so that when it calls an FX sequence thread it waits for it.
I am glad you told me about the timing thing. That was part of the reason I decided to have fxmaster_thread wait. The other reasons are some of the FX sequnces use the same func_exploders so I didn't know how Sin might react if multiple threads were triggering the same entities (this would be hard to test for it could work for hours, days weeks before that wrong combination of events occur or even worse it could work fine durring testing only to find that it doesn't work for half the people who run it.)
It just seemed unwise to try such a thing when I am so unfamiliar with this programming environment. Also multiple FX sequence threads running at the same time could cause too many effects to occur in the game at the same time, causing the game to lag. (This is a DM level so it has to work online)
The script I have now is quite a bit bigger than the one I posted earlier.
It seems to be working fine. However if you want to see it I can post it here. Just let me know (I am at work right now so I can't at the moment.)
Your advice about timing was very valuable. I would have never figured that out. I can see that Sin scripting is radically different than the structured (and a bit of OO as well) programming I am used to. I work mainly with Borland's Delphi, Paradox and its associated language ObjectPal. It looks like I am going to have to learn a new mind set

------------------
claudec is offline   Reply With Quote
Old 05-24-1999, 11:27 PM   #4
eutectic
Fanboy
 
Join Date: Jan 1999
Posts: 844
Default Re: How do you do open thread and looping? I keep getting infinate loop error.

Thanks. I'm glad that helped you. One thing about what you said:

The other reasons are some of the FX sequnces use the same func_exploders so I didn't know how Sin might react if multiple threads were triggering the same entities (this would be hard to test for it could work for hours, days weeks before that wrong combination of events occur or even worse it could work fine durring testing only to find that it doesn't work for half the people who run it.)

Well multiple threads can act upon the same entities as long as you make sure ONLY 1 thread acts upon those at a time. Sin WILL react badly (could even crash) if 2 separate threads or 2 separate instances (or more) of the same thread try to trigger the same entities at the same time. Best case, it would create spurious or uncontrolled triggerings.

But there is a way to prevent this with the "ifthreadactive" and "ifthreadnotactive" commands. Those use the parm.previousthread variable for testing (same as waitForThread). Or having a master thread from which all the secondary threads are called.

------------------
The Node
www.ritualistic.com/node

The official Sin entities and scripting reference site


[This message has been edited by eutectic (edited 05-24-99).]
eutectic is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:17 PM.


Powered by vBulletin® Version 3.6.3
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.