Stuck In An Infinite Loop.

Post » Sat May 28, 2011 12:03 am

Thread revived for a new issue! Please see post #10.
User avatar
Elina
 
Posts: 3411
Joined: Wed Jun 21, 2006 10:09 pm

Post » Fri May 27, 2011 5:33 pm

Is there something setting warp back to 1 again? Maybe post your whole script so we can look at it.
User avatar
Ludivine Poussineau
 
Posts: 3353
Joined: Fri Mar 30, 2007 2:49 pm

Post » Sat May 28, 2011 2:06 am

Here it is. It's just strange that after figuring all this out (with the ever-helpful MW Scripting for Dummies) it's this one thing that stops the show. But I guess that's what everyone starting out says. I changed some variable names, too. Thanks again.

Begin zs_winescript3short OnPCEquipshort alreadyshort waitfloat wtimerfloat ftimershort dofadeshort warpreadyif ( MenuMode == 1 )	Returnendifset already to ( GetPCCell Cellname ) ;check if you're already thereif ( OnPCEquip == 1) ;you've equipped the bottle	if ( already == 1 )		MessageBox "The cork is stuck."		set OnPCEquip to 0	else		MessageBox "You drink from the bottle of wine."		set wait to 1		set OnPCEquip to 0	endifendifif ( wait == 1 ) ;initiate warp timer	if ( wtimer < 3 )		set wtimer to ( wtimer + GetSecondsPassed )		MessageBox "wtimer is %f" wtimer ;tells how much	endifendifif ( wtimer > 3.0 ) ;fade out	set wait to 0	FadeOut 3.0	set wtimer to 0	set dofade to 1endifif ( dofade == 1 ) ;initiate fade timer	if ( ftimer < 3 )		set ftimer to ( ftimer + GetSecondsPassed )		MessageBox "ftimer is %f" ftimer ;tells how much	endifendifif ( ftimer > 3 ) ; fade in	set dofade to 0	set ftimer to 0	set warpready to 1	FadeIn 3.0endifif ( warpready == 1 ) ;warp	set warpready to 0	player->PositionCell 0 0 10 0 Cellname	MessageBox "warp complete"endifEnd zs_winescript3



[EDIT] I managed to fix the issue. I took your advice about something setting warp back and I added another if check before ( ftimer>3 ). Seems to be working 100% now. Thank you.
User avatar
Marquis T
 
Posts: 3425
Joined: Fri Aug 31, 2007 4:39 pm

Post » Fri May 27, 2011 2:21 pm

Just a quick glance tells me that if the timer ever happens to stop exactly on 3, your script won't work.
User avatar
Jessica White
 
Posts: 3419
Joined: Sun Aug 20, 2006 5:03 am

Post » Fri May 27, 2011 5:56 pm

That hadn't crossed my mind. Until, of course, it happened. Precisely 3.0000000. :rolleyes: But I'll have to remember that.
User avatar
megan gleeson
 
Posts: 3493
Joined: Wed Feb 07, 2007 2:01 pm

Post » Fri May 27, 2011 5:57 pm

Even if I call StopScript. What's the deal with StopScript, anyway? Does it just not work for some types of scripts?
If your script is attached to a bottle, then StopScript won't stop it. It only works on scripts that were previously StartScripted elsewhere.
User avatar
Emily Graham
 
Posts: 3447
Joined: Sat Jul 22, 2006 11:34 am

Post » Fri May 27, 2011 2:42 pm

Correct. StopScript only works for global scripts not local ones, because the object the script is attached to is continually calling the script. If you want to stop a local script from executing after the action is done, it's best to check for the completed condition at the top of the script and create a return. That way, once everything is done, the script will just hit the return and never continue again.

I use this often with NPCs with long scripts. If they're dead, I make a check for that and kill the script with a return at the top.
User avatar
Inol Wakhid
 
Posts: 3403
Joined: Wed Jun 27, 2007 5:47 am

Post » Fri May 27, 2011 11:59 pm

So you are saying that I cannot "fully stop" a script on an object unless the object is removed. But I can halt the script at the first line. Okay. This is making more and more sense. My bottle script is perfect now!

What if, say, I attach a script to a bottle that, when used, StartScripts another script then removes the bottle? Would that make the started script a global one? I don't intend to do use this the moment, but it seemed a good question to ask.
User avatar
Andrew Tarango
 
Posts: 3454
Joined: Wed Oct 17, 2007 10:07 am

Post » Fri May 27, 2011 10:14 am

Yes. I've done a similar thing to simulate the drinking of a scripted potion. Because you need to skip equip to make sure the entire script on the potion is executed, you then need to start a global script to finish off the job once the potion is swallowed. The script started from the potion's local script is a global one which can be stopped using the StopScript command. You then use the global script to remove the potion from the player's inventory, play the swallow sound (because it won't be played otherwise because you skipped equipping the potion) and finish off whatever you need to do.

In fact, in the case of scripted potions, the best thing to do is have the local script only use the StartScript if you only want it to perform after the potion is swallowed, and relegate the rest of the action to the global script that it starts.
User avatar
Sammygirl500
 
Posts: 3511
Joined: Wed Jun 14, 2006 4:46 pm

Post » Fri May 27, 2011 12:59 pm

Hey again, minor bit of thread necromancy, but I figured it was better than starting a new one. I've got a new problem, and the documentation I have isn't being very helpful.

I'm using MWSE to insert names as strings into message boxes, and the buttons are options you can toggle on or off. The issue I need to fix is that you can't tell whether an option is on or off. I want to add a suffix to each button that says (On) or (Off). But nothing I can find in the material I have says how to append strings onto strings.

Basically, does anyone know how to take a string like Option Name and add an (On) so it will read Option Name (On)?
User avatar
^_^
 
Posts: 3394
Joined: Thu May 31, 2007 12:01 am

Post » Fri May 27, 2011 2:28 pm

Can't you just use xStringBuild (ie setx stringvar to xStringBuild "%s (off)" stringvar)?
User avatar
Dean Ashcroft
 
Posts: 3566
Joined: Wed Jul 25, 2007 1:20 am

Post » Fri May 27, 2011 9:13 pm

That was the first plan, but it's messy and slow. The menu has eight options, and I have to check all of them in big ol' if-blocks. But so far, that looks like my only option. Thanks anyway. :)
User avatar
kasia
 
Posts: 3427
Joined: Sun Jun 18, 2006 10:46 pm

Post » Sat May 28, 2011 12:22 am

Ah, I see... Sorry, I can't think of anything better :(
User avatar
evelina c
 
Posts: 3377
Joined: Tue Dec 19, 2006 4:28 pm


Return to III - Morrowind