Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: while end_while query

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Byg's Avatar Read The Manual
    Patrician

    Join Date
    Nov 2005
    Posts
    4,569

    Default while end_while query

    Why does this not work and how do I make it work?
    I know nothing about "while" and only found 2 incidental examples in the entire tutorial section.
    I want those if statement to keep running in the while loop until the depleted counter value "mainbag" causes an exit from the while loop.


    ; While code test
    ;------------------------------------------
    ; Task to spread mainbag value evenly among bag1,bag2 etc when the corresponding counters owned1 owned2 etc have a value of 1. To be triggered when a unit is recruited (though any trigger will do)
    ; should deduct 50 money from treasury (which is my way of checking it works), but does not.

    ;so, bag one and bag 2 are owned so the 100 in mainbag needs distributing into those 2 bags.
    ;therefore each bag should get 50 and as the only enabled console command for money is in the bag1 section, 50 should get removed from treasury.


    declare_counter mainbag 0

    set_event_counter owned1 1
    set_event_counter owned2 1
    set_event_counter owned3 0
    set_event_counter bag1 0
    set_event_counter bag2 0
    set_event_counter bag3 0

    monitor_event AddedToTrainingQueue FactionIsLocal
    set_counter mainbag 100
    end_monitor


    while I_CompareCounter mainbag > 0

    if I_EventCounter owned1 = 1
    inc_counter mainbag -1
    inc_event_counter bag1 1 ; I want this bag to fill up with 50
    console_command add_money -1 ; to check this I hope to see 50 getting removed from the treasury
    end_if

    if I_EventCounter owned2 = 1
    inc_counter mainbag -1
    inc_event_counter bag2 1 ; and I want this bag to fill up with 50
    ; console_command add_money -1 ; this line disabled for current test
    end_if

    if I_EventCounter owned3 = 1
    inc_counter mainbag -1
    inc_event_counter bag3 1
    console_command add_money -1 ; this section should not get triggered in this test
    end_if

    end_while
    Last edited by Byg; February 18, 2011 at 05:14 PM.

    NEW BGR V 20150324! . . . . . . . .. . . .BGRIV_E

  2. #2
    Gorrrrrn's Avatar Citizen
    Join Date
    Jan 2007
    Location
    here
    Posts
    5,546

    Default Re: while end_while query

    I expect someone will say this is wrong but my guess is that while needs to be inside some sort of larger statement, rather than sitting there on its own?

    have you tried moving the end_monitor to after the end_while ?

    or maybe embedding it inside the if statements?

    does it work for a single if statement ?

    In docudemons it looks as if it works the same as if statements.

    (I'll remove this when someone comes up with the right answer. = apparently suggestion 1 is the correct answer so no need to remove this after all )
    Last edited by Gorrrrrn; February 19, 2011 at 06:51 AM.

  3. #3
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: while end_while query

    Look at scripting for historic battles if you want to get a rough idea of how to use while/end_while. I haven't had any use for it, so I'm barely familiar with what's going on.

    Here's an example of a monitor containing whiles from the agincourt script:
    Code:
    	monitor_conditions I_CompareCounter start_battle = 0
    
    		camera_position_at_bookmark 1		; Landscape shot (farm and windmill)-START
    		
    		unit_order_move_relative eng_dis_general_1 0 300
    	 	unit_order_move_relative eng_dis_knights_1 0 300
    	 	unit_order_move_relative eng_dis_knights_2 0 300
    	 	unit_order_move_relative eng_dis_knights_3 0 300
    	 	unit_order_move_relative eng_heavy_bill_1 0 300
    	 	unit_order_move_relative eng_heavy_bill_2 0 300
    	 	unit_order_move_relative eng_dis_knights_4 0 300
    	 	unit_order_move_relative eng_yeomen_1 0 300
    	 	unit_order_move_relative eng_yeomen_2 0 300
    	 	unit_order_move_relative eng_yeomen_3 0 300
    	 	unit_order_move_relative eng_yeomen_4 0 300
    	 	unit_order_move_relative eng_yeomen_5 0 300
    	 	unit_order_move_relative eng_yeomen_6 0 300
    	 	unit_order_move_relative eng_yeomen_7 0 300
    
    		battle_wait 2
    
    		while I_CompareCounter start_battle = 1
    		end_while
    
    ;;;Intro landscape shot
    ;;;;;;;;;;;;;;;;;;;;;;;		
    	 	;"1415, Northern France"
    	 	play_sound_event AGINCOURT_NARRATOR_1 tag = AGINCOURT_NARRATOR_1
    	 	
    	 	battle_wait 2
    		while I_CompareCounter start_battle = 1
    		end_while
    ;;;Henry's army marching along road
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;		
    		camera_zoom_to_bookmark 2 30		; over head shot of henry's army
    		battle_wait 5  
    	   	;"The Hundred Years War continues.:
    		play_sound_event AGINCOURT_NARRATOR_2 tag = AGINCOURT_NARRATOR_2
    	 	
    	 	battle_wait 4
    		while I_CompareCounter start_battle = 1
    		end_while
    
    ;;;;camera over henry
    ;;;;;;;;;;;;;;;;;;;;;			 	
    	 	 camera_position_at_bookmark 3	; Road where Eng enter (right close-up)
    	 	 battle_wait 1
    	 	while I_CompareCounter start_battle = 1
    		end_while
    	 	; "After spending the Autumn month campaigning in Northern France, Henry V, King of England is making his way home."
    		play_sound_event AGINCOURT_NARRATOR_3 tag = AGINCOURT_NARRATOR_3
    		
    		battle_wait 8
    		while I_CompareCounter start_battle = 1
    		end_while
    ;;;shot over French camp
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;		
    		camera_position_at_bookmark 6		; Overhead shot of French camp
    		battle_wait 1 
    		;"But first he must contend with a large army awaiting him near the town of Agincourt."
    		play_sound_event AGINCOURT_NARRATOR_4 tag = AGINCOURT_NARRATOR_4
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    ;;;;;Shot of French army
    ;;;;;;;;;;;;;;;;;;;;;;;;		
    		camera_position_at_bookmark 21		; French army
    		battle_wait 3
    		while I_CompareCounter start_battle = 1
    		end_while
    ;;;;Shot of Town
    ;;;;;;;;;;;;;;;;;;
    		camera_position_at_bookmark 5 		; Overhead shot of Agincourt pt1
    		
    		
    	;;;************************************************************
    	;;; Look at French generals	& the french army
    	;;;-----------------------------------------------------------	
    				
    		battle_wait 3
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    		camera_position_at_bookmark 15			; close up of French general 1
    		;battle_wait 1
    		;"The French army, led by John la Maingre and Charles d’ Albert is more a collection of arrogent nobles than an army, distracted by their own bitter rivalries.
    		play_sound_event AGINCOURT_NARRATOR_5 tag = AGINCOURT_NARRATOR_5	
    		battle_wait 3
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    		camera_position_at_bookmark 16			; close up of French general 2 (follow him)
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    	;;;	Move French group1 along road
    	;;;----------------------------------------------------------------------
    	
    		unit_order_move_relative fra_general_2 0 100
    		unit_order_move_relative fra_chiv_knights_1a 0 100 
    		unit_order_move_relative fra_chiv_knights_2a 0 100  	
    		
    		camera_track_unit fra_general_2 front 8 1 -25
    		
    	;;;------------------------------------------------------------------------------	
    	;;;Move English to 'coming off road position' & get them to move towards position 1
    	;;;------------------------------------------------------------------------------	
    		battle_wait 5
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    		unit_immediate_place	eng_dis_general_1 -226.762, -187.262 -69 10.886
    	 	unit_immediate_place	eng_dis_knights_1 -264.875, -185.188 41 2.807
    		unit_immediate_place	eng_dis_knights_2 -255.256, -170.542 36 6.738
    		unit_immediate_place	eng_dis_knights_3 -252.595, -154.884 12 7.672
    		unit_immediate_place	eng_heavy_bill_1 -271.205, -177.868 34 3.606
    		unit_immediate_place	eng_heavy_bill_2 -283.017, -193.595 60 1.990
    		unit_immediate_place	eng_dis_knights_4 -279.872, -201.320 62 5.145
    		unit_immediate_place	eng_yeomen_1 -241.149, -178.122, 30 8.509
    		unit_immediate_place	eng_yeomen_2 -230.708, -157.315, 23 4.893
    		unit_immediate_place	eng_yeomen_3 -275.787, -160.847, 33 2.212
    		unit_immediate_place	eng_yeomen_4 -255.289, -197.273, 29 5.450
    		unit_immediate_place	eng_yeomen_5 -298.654, -177.644, 83 5.588
    		unit_immediate_place	eng_yeomen_6 -292.560, -214.850, 86 3.823
    		unit_immediate_place	eng_yeomen_7 -268.302, -213.126, 88 6.102
    		
    		unit_order_move eng_dis_knights_1 -207.594, -88.063, -1
    		unit_order_move eng_dis_knights_2 -182.588, -94.531, -1
    		unit_order_move eng_dis_knights_3 -203.524, -94.976, -1
    		unit_order_move eng_heavy_bill_1  -233.293, -101.524, 2
    		unit_order_move eng_heavy_bill_2  -123.461, -100.933, -1
    		unit_order_move eng_dis_knights_4 -160.895, -93.913, 0,
    		unit_order_move eng_yeomen_1 -280.087, -76.373, 28
    		unit_order_move eng_yeomen_2 -244.755, -93.495, 3
    		unit_order_move eng_yeomen_3 -210.006, -104.321, -1
    		unit_order_move eng_yeomen_4 -168.697, -103.790, -1
    		unit_order_move eng_yeomen_5  -139.107, -93.584, -1
    		unit_order_move eng_yeomen_6 -99.213, -91.268, -22
    		unit_order_move eng_yeomen_7 -100.853, -102.349, -14
    		
    		battle_wait 3	
    		while I_CompareCounter start_battle = 1
    		end_while
    	
    		camera_position_at_bookmark 9 ;side shot of Eng coming off road
    		battle_wait 1 
    		while I_CompareCounter start_battle = 1
    		end_while
    
    		; "While the English army is a disciplined force, led by King Henry, a shrewd commander and an inspiring presence."
    		play_sound_event AGINCOURT_NARRATOR_6 tag = AGINCOURT_NARRATOR_6
    		battle_wait 3
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    		camera_zoom_to_bookmark 7 5 ;Close up of Henry from his right side
    		
    		battle_wait 4
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    		camera_zoom_to_bookmark 8 4 ; view behind Henry of of Eng coming off road
    		battle_wait 2
    		while I_CompareCounter start_battle = 1
    		end_while
    
    		;"As the sun rises on the 25th October, Henry moves his weary and hungry men into position, knowing they are largely outnumbered."
    		play_sound_event AGINCOURT_NARRATOR_7 tag = AGINCOURT_NARRATOR_7
    		
    			
    		battle_wait 9
    		while I_CompareCounter start_battle = 1
    		end_while
    	
    	;;;******************************************************************************	
    	;;;Shots of battlefield
    	;;;------------------------------------------------------------------------------	
    			
    		camera_position_at_bookmark 18	;Point 1 view of battlefield
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    
    		;"Heavy rainfall overnight has left the newly ploughed field separating the two forces, a sodden muddy mess."
    		play_sound_event AGINCOURT_NARRATOR_8 tag = AGINCOURT_NARRATOR_8
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    
    		camera_zoom_to_bookmark 19 20 ; Point 2 view of battlefield
    	
    			
    	;;;------------------------------------------------------------------------
    	;;;	Teleport French group1 to battle start position
    	;;;----------------------------------------------------------------------		
    		unit_immediate_place fra_general_2 -757.765, 120.540, -180, 29.641
    		unit_immediate_place fra_chiv_knights_1a -796.416, 116.579, 175 31.499
    		unit_immediate_place fra_chiv_knights_2a -774.006, 140.297, 177 33.830
    		
    	;;;****************************************************************************
    	;;; Shots of relaxed French army
    	;;;--------------------------------------------------------------------------
    		
    		battle_wait 7	
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    		camera_position_at_bookmark 20	; French camp fire
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    		;"The French forces awake and take a leisurely breakfast, happy to wait and let disease and hunger grind down Henry’s Army."
    		play_sound_event AGINCOURT_NARRATOR_9 tag = AGINCOURT_NARRATOR_9
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    ; 		unit_order_move_relative fra_dis_chiv_knig_3 0 30
    ; 	 	unit_order_move_relative fra_dis_chiv_knig_5 0 30
    ; 	 	unit_order_move_relative fra_dis_chiv_knig11 0 30
    		
    		
    	 	battle_wait 2
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    		camera_position_at_bookmark 13 ; relaxed french
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    
    		
    		 
    	;;;-----------------------------------------------------------------------------
    	;;; teleport Eng army to battle position 1 in formation
    	;;;----------------------------------------------------------------------------
    	
    		
    		unit_immediate_place	eng_dis_general_1  -184.844, -88.415, -1 21.133
    	 	unit_immediate_place	eng_dis_knights_1 -207.594, -88.063, -1 21.949
    		unit_immediate_place	eng_dis_knights_2 -182.588, -94.531, -1 21.623
    		unit_immediate_place	eng_dis_knights_3 -203.524, -94.976, -1 21.931
    		unit_immediate_place	eng_heavy_bill_1 -233.293, -101.524, 2 20.583
    		unit_immediate_place	eng_heavy_bill_2 -123.461, -100.933, -1 20.817
    		unit_immediate_place	eng_dis_knights_4 -160.895, -93.913, 0 21.542
    		unit_immediate_place	eng_yeomen_1 -280.087, -76.373, 28 34.117
    		unit_immediate_place	eng_yeomen_2 244.755, -93.495, 3 40.926
    		unit_immediate_place	eng_yeomen_3 -210.006, -104.321, -1 38.569
    		unit_immediate_place	eng_yeomen_4 -168.697, -103.790, -1 60.078
    		unit_immediate_place	eng_yeomen_5 -139.107, -93.584, -1 39.414
    		unit_immediate_place	eng_yeomen_6 -99.213, -91.268, -22 39.938
    		unit_immediate_place	eng_yeomen_7 -100.853, -102.349, -14 40.189
    	
    		
    	;;;-----------------------------------------------------------------------------
    	;;; move Eng army towards battle position 2 in formation
    	;;;----------------------------------------------------------------------------
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    
    	 	unit_order_move_relative eng_dis_general_1 0 90
    	 	unit_order_move_relative eng_dis_knights_1 0 90
    	 	unit_order_move_relative eng_dis_knights_2 0 90
    	 	unit_order_move_relative eng_dis_knights_3 0 90
    	 	unit_order_move_relative eng_heavy_bill_1 0 90
    	 	unit_order_move_relative eng_heavy_bill_2 0 90
    	 	unit_order_move_relative eng_dis_knights_4 0 90
    	 	unit_order_move_relative eng_yeomen_1 0 90
    	 	unit_order_move_relative eng_yeomen_2 0 90
    	 	unit_order_move_relative eng_yeomen_3 0 90
    	 	unit_order_move_relative eng_yeomen_4 0 90
    	 	unit_order_move_relative eng_yeomen_5 0 90
    	 	unit_order_move_relative eng_yeomen_6 0 90
    	 	unit_order_move_relative eng_yeomen_7 0 90
    		
    	;;;*********************************************************************	 
    	;;; Shots of Eng army moving into position 1
    	;;;-----------------------------------------------------------------------	 	
    		
    		battle_wait 5
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    		camera_position_at_bookmark	10 ; eng army starting to move from position 1 to position 2
    		battle_wait 3
    		while I_CompareCounter start_battle = 1
    		end_while
    	 
    		;"Knowing this only too well Henry moves his army forward, hoping to provoke the French into rash action."
    		play_sound_event AGINCOURT_NARRATOR_10 tag = AGINCOURT_NARRATOR_10
    		 battle_wait 3
    		while I_CompareCounter start_battle = 1
    		end_while
    		 
    		 camera_position_at_bookmark 11 ; Point1-following eng army moving from position 1 to position 2
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    		camera_zoom_to_bookmark 12 1	; Point2-following eng army moving from position 1 to position 2
    		battle_wait 4
    		while I_CompareCounter start_battle = 1
    		end_while
    
    		;"Henry’s gamble is successful."
    		play_sound_event AGINCOURT_NARRATOR_11 tag = AGINCOURT_NARRATOR_11
    		
    	;;;--------------------------------------------------------------------------------------------------
    	;;;Move French towards battle position
    	;;;--------------------------------------------------------------------------------------------------
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    			
    		unit_order_move fra_dis_chiv_knig_1 -185.213, 183.259, -179 run
    		unit_order_move fra_dis_chiv_knig_2 -106.470, 183.674, -180 run
    		unit_order_move fra_dis_chiv_knig_3  -122.455, 248.714, -179 run
    		unit_order_move fra_dis_chiv_knig_4 -132.375, 183.985, -180 run
    		unit_order_move fra_crossbow_1 -78.575, 190.072, -179 run
    		unit_order_move fra_crossbow_2 -176.583, 190.499, -180 run 
    		unit_order_move fra_dis_chiv_knig_5 -150.806, 227.054, -180 run
    		unit_order_move fra_dis_chiv_knig_6 -176.784, 226.796, -180 run 
    		unit_order_move fra_dis_chiv_knig_7 -158.946, 183.474, -180 run 
    		unit_order_move fra_serg_spearmen_1 -101.301, 248.914, -180 run 
    		unit_order_move fra_serg_spearmen_2 -172.323, 248.801, 178 run
    		unit_order_move fra_chiv_knights_1  -201.045, 166.681, 179 run
    		unit_order_move fra_chiv_knights_2 -171.840, 236.934, -180 run
    		unit_order_move fra_dis_chiv_knig_8 -145.452, 190.022, -179 run
    		unit_order_move fra_dis_chiv_knig_9 -147.297, 248.818, -180 run
    		unit_order_move fra_dis_chiv_knig10 -98.537, 227.391, 179 run
    		unit_order_move fra_chiv_knights_3 -91.680, 166.402, 179 run
    		unit_order_move fra_dis_chiv_knig11 -136.175, 235.577, -180 run
    		unit_order_move fra_general_1 -124.856, 227.657, -180 run
    		
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    		
    	;;;-----------------------------------------------------------------------------
    	;;; teleport Eng army to battle position 2 in formation & plant stakes & make henry never rout
    	;;;----------------------------------------------------------------------------
    		
    		unit_immediate_place	eng_dis_general_1 -181.080, -17.841, -1 21.133
    		unit_immediate_place	eng_dis_knights_1 -216.230, -25.426, -1 21.949
    	 	unit_immediate_place	eng_dis_knights_2 -179.796, -3.408, -1 21.623
    		unit_immediate_place	eng_dis_knights_3 -200.327, -3.566, -1 21.931
    		unit_immediate_place	eng_heavy_bill_1 -239.817, -22.258, 2 20.583
    		unit_immediate_place	eng_heavy_bill_2 -119.218, -23.444, -1 20.817
    		unit_immediate_place	eng_dis_knights_4 -158.669, -3.042, 0 21.542
    		unit_immediate_place	eng_yeomen_1 -271.688, 12.155, 28 28
    		unit_immediate_place	eng_yeomen_2 -241.397, -3.124, 3 31
    		unit_immediate_place	eng_yeomen_3 -220.219, -19.615, -1 35
    		unit_immediate_place	eng_yeomen_4 -159.687, -18.999, -1 35
    		unit_immediate_place	eng_yeomen_5 -137.490, -4.188, -1 30
    		unit_immediate_place	eng_yeomen_6 -98.317, -2.234, -22 31
    		unit_immediate_place	eng_yeomen_7 -107.482, -18.187, -14 31
    		
    	 	 		  		
    	  	unit_deploy_stakes eng_yeomen_1
    	  	unit_deploy_stakes eng_yeomen_2
    	  	unit_deploy_stakes eng_yeomen_3
    	  	unit_deploy_stakes eng_yeomen_4
    	  	unit_deploy_stakes eng_yeomen_5
    	  	unit_deploy_stakes eng_yeomen_6
    	  	unit_deploy_stakes eng_yeomen_7
    	  	
    	  	
    		unit_set_skirmish_mode eng_yeomen_1 off
    		unit_set_skirmish_mode eng_yeomen_2 off
    		unit_set_skirmish_mode eng_yeomen_3 off
    		unit_set_skirmish_mode eng_yeomen_4 off
    		unit_set_skirmish_mode eng_yeomen_5 off
    		unit_set_skirmish_mode eng_yeomen_6 off
    		unit_set_skirmish_mode eng_yeomen_7 off
    		
    		unit_set_morale eng_dis_general_1 high
    	;;;*******************************************************************************	
    	;;; SHOT of French rushing into position
    	;;;--------------------------------------------------------------------------------  	
    	
    		camera_position_at_bookmark 4 ; French army on the move
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    
    		;"Lines of unprepared knights and nobles push and shove amongst themselves, eager to engage their English counterparts."
    		play_sound_event AGINCOURT_NARRATOR_12 tag = AGINCOURT_NARRATOR_12 
    		battle_wait 6
    		while I_CompareCounter start_battle = 2
    		end_while
    
    		camera_position_at_bookmark 17  ; French army on the move2
    		battle_wait 5
    		while I_CompareCounter start_battle = 1
    		end_while
    	
    	;;;-------------------------------------------------------------------
    	;;; New Bookmarks
    	;;;-----------------------------------------------------------------
    	
    		set_camera_bookmark 1, -230.261, 75.4718, 7.75472		-224.515, 75.6336, -0.403302	; shot of stakes	 
    		set_camera_bookmark 2, -159.791, 73.8077, -15.8261		-164.508, 68.3991, -23.2231		; eng men at arms in battle line  
    		set_camera_bookmark 3, -183.138, 72.378, -15.6563		-177.229, 73.238, -23.7172		; henry in battle line		
    		set_camera_bookmark 4, -178.735, 89.2306, -61.7882		-177.809, 85.2347, -52.9387		; Eng overview
    		set_camera_bookmark 5, -66.9693, 73.0177, 12.3019		-63.9737, 76.9757, 3.35406		; Point 1 Shot of archers		
    		set_camera_bookmark 6, -76.6844, 74.1679, 8.90294		-71.7806, 74.4139, 0.231824		; Point 2 Shot of archers
    		
    	;;;*********************************************************************************
    	;;; SHOT of Eng archers in position
    	;;;------------------------------------------------------------------------------
    	
    		camera_position_at_bookmark 5 ; Point 1 Shot of archers
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    			
    		camera_zoom_to_bookmark 6 1 ; Point 2 Shot of archers
    		;"Henry's longbowmen will be the key to defeating the French, striking them down as they traverse the muddy field." 
    		play_sound_event AGINCOURT_NARRATOR_13 tag = AGINCOURT_NARRATOR_13
    		
    	;;--------------------------------------------------------------------
    	;;;teleport FrencH group0 to battle position
    	;;---------------------------------------------------------------------
    	
    		unit_immediate_place fra_general_1 -124.856, 227.657, -180  26.596 
    		unit_immediate_place fra_dis_chiv_knig_1 -185.213, 183.259, -179 26.912
    		unit_immediate_place fra_dis_chiv_knig_2 -106.470, 183.674, -180 26.258
    		unit_immediate_place fra_dis_chiv_knig_3  -122.455, 248.714, -179 25.942
    		unit_immediate_place fra_dis_chiv_knig_4 -132.375, 183.985, -180 26.272
    		unit_immediate_place fra_crossbow_1 -78.575, 190.072, -179 72.701
    		unit_immediate_place fra_crossbow_2 -176.583, 190.499, -180 83.668
    		unit_immediate_place fra_dis_chiv_knig_5 -150.806, 227.054, -180  26.080
    		unit_immediate_place fra_dis_chiv_knig_6 -176.784, 226.796, -180 26.576
    		unit_immediate_place fra_dis_chiv_knig_7 -158.946, 183.474, -180 26.892
    		unit_immediate_place fra_serg_spearmen_1 -101.301, 248.914, -180 21.449
    		unit_immediate_place fra_serg_spearmen_2 -172.323, 248.801, 178 21.791
    		unit_immediate_place fra_chiv_knights_1  -201.045, 166.681, 179 63.351
    		unit_immediate_place fra_chiv_knights_2 -171.840, 236.934, -180 49.735
    		unit_immediate_place fra_dis_chiv_knig_8 -145.452, 190.022, -179 26.572
    		unit_immediate_place fra_dis_chiv_knig_9 -147.297, 248.818, -180 25.219
    		unit_immediate_place fra_dis_chiv_knig10 -98.537, 227.391, 179 26.312
    		unit_immediate_place fra_chiv_knights_3 -91.680, 166.402, 179 94.343
    		unit_immediate_place fra_dis_chiv_knig11 -136.175, 235.577, -180 26.312	
    		
    	;;;-------------------------------------------------------------------
    	;;; New Bookmarks
    	;;;-----------------------------------------------------------------
    	
    		set_camera_bookmark 1, -230.461, 75.2703, 6.77397		-224.787, 75.1728, -1.41667		; shot of stakes	 
    		set_camera_bookmark 2, -159.791, 73.8077, -15.8261		-164.508, 68.3991, -23.2231		; eng men at arms in battle line  
    		set_camera_bookmark 3, -183.068, 72.7352, -15.8828		-178.101, 72.0334, -24.4757		; henry in battle line		
    		set_camera_bookmark 4, -178.735, 89.2306, -61.7882		-177.809, 85.2347, -52.9387		; Eng overview
    		set_camera_bookmark 20, -66.7741, 74.373, 12.5999		-63.3339, 73.5149, 2.62728		; Point 1 Shot of archers		
    		set_camera_bookmark 21, -134.848, 75.1649, -0.950766	-64.8983, 72.6332, 2.85072		; Point 2 Shot of archers
    			
    		battle_wait 9
    		while I_CompareCounter start_battle = 1
    		end_while
    
    	;	"To protect his longbowmen from cavalry, Henry has ordered them to plant sharpened stakes in front of their positions."
    		play_sound_event AGINCOURT_NARRATOR_14 tag = AGINCOURT_NARRATOR_14
    		battle_wait 2
    		while I_CompareCounter start_battle = 1
    		end_while
    
    	;;;************************************************************************
    	;;; SHOT of stakes
    	;;;-------------------------------------------------------------------------		
    		
    		camera_position_at_bookmark 1	; shot of stakes
    			
    		battle_wait 7
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    	;;;************************************************************************
    	;;; SHOT of men at arms, Henry and final shot of Eng army
    	;;;-------------------------------------------------------------------------
    			
    		camera_position_at_bookmark 2 ; eng men at arms in battle line
    		battle_wait 1
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    		
    		camera_zoom_to_bookmark 3 4 ; henry in battle line
    			;"To emerge victorious, Henry must survive the upcoming battle and destroy or rout the French army before him, Only then can he make his way home.
    		play_sound_event AGINCOURT_NARRATOR_15 tag = AGINCOURT_NARRATOR_15
    		
    		battle_wait 10
    		while I_CompareCounter start_battle = 1
    		end_while
    		
    		camera_zoom_to_bookmark 4 15 ; Eng overview
    		
    		battle_wait 7
    		
    		set_counter start_battle 1
    		
    		terminate_monitor
    	end_monitor
    Given the agincourt example I'd be looking for real-time applications, it seems to me that's what whiles may be for. Could be useful for scripted camera movements, and so on, on the campaign map too, I'd guess.
    Last edited by Taiji; February 18, 2011 at 06:31 PM.

  4. #4

    Icon1 Re: while end_while query

    Byg: If you look at the examples that Taiji posted, ‘while’ is always followed by ‘end_while’ so the front of your script need to look like this:
    Spoiler Alert, click show to read: 
    Code:
    	monitor_event AddedToTrainingQueue IsLocal
    		set_counter mainbag 100
    		while I_CompareCounter mainbag > 0
    	end_while

    Also I'm pretty sure that you need to add a faction’s name to the ‘add_money’ command:
    Spoiler Alert, click show to read: 
    Code:
    		if I_EventCounter owned1 = 1
    		inc_counter mainbag -1
    		inc_event_counter bag1 1
    		console_command add_money england -50
    	end_if
    		if I_EventCounter owned2 = 1
    		inc_counter mainbag -1
    		inc_event_counter bag2 1
    		; console_command add_money england -50
    	end_if
    		if I_EventCounter owned3 = 1
    		inc_counter mainbag -1
    		inc_event_counter bag3 1
    		console_command add_money england -50
    	end_if
    	end_monitor

    Code:
    declare_counter mainbag
    
    set_event_counter owned1 1
    set_event_counter owned2 1
    
    	monitor_event AddedToTrainingQueue IsLocal
    		set_counter mainbag 100
    		while I_CompareCounter mainbag > 0
    	end_while
    
    		if I_EventCounter owned1 = 1
    		inc_counter mainbag -1
    		inc_event_counter bag1 1
    		console_command add_money england -50
    	end_if
    		if I_EventCounter owned2 = 1
    		inc_counter mainbag -1
    		inc_event_counter bag2 1
    		; console_command add_money england -50
    	end_if
    		if I_EventCounter owned3 = 1
    		inc_counter mainbag -1
    		inc_event_counter bag3 1
    		console_command add_money england -50
    	end_if
    	end_monitor

  5. #5
    Byg's Avatar Read The Manual
    Patrician

    Join Date
    Nov 2005
    Posts
    4,569

    Default Re: while end_while query

    Thanks for your suggestions. In all cases though those while - end_while examples appear to be just used as a pause, not effecting anything whilst they are true. Please feel free to correct me.

    You don't need to put a faction name for add_money.

    I'll try that last suggestion just to see, but I strongly suspect that the if statements will only occur once (in which case the while is redundant), when I want the process to repeat until done with a single AddedToTrainingQueue

    NEW BGR V 20150324! . . . . . . . .. . . .BGRIV_E

  6. #6
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: while end_while query

    Quote Originally Posted by Byg View Post
    Thanks for your suggestions. In all cases though those while - end_while examples appear to be just used as a pause, not effecting anything whilst they are true. Please feel free to correct me.
    You're welcome.

    Quote Originally Posted by Byg View Post
    Success. All code as shown in my original script, but I simply moved the word "end_monitor" to the end. To me that seems an illogical format, but there you are. Now I have a number crunching system to help process some of the complex ideas for BGRV.
    Cool, thanks for sharing

    In your example what advantage is offered over an if statement?
    Last edited by Taiji; February 19, 2011 at 06:52 AM.

  7. #7
    Byg's Avatar Read The Manual
    Patrician

    Join Date
    Nov 2005
    Posts
    4,569

    Default Re: while end_while query

    Quote Originally Posted by Taiji View Post


    Cool, thanks for sharing

    In your example what advantage is offered over an if statement?
    This will repeatedly run through the ifs until the job is done. The if on their own would only run once. To sort the main counter's value of 100 (100 wont be the only value I use) using only ifs into 3 other counters would have taken 300 ifs. My method does it with 3 and it would still be 3 if I needed to share a value of 10,000.

    It may even take longer than the individual ifs, but it does not matter as it is being triggered by the player during his turn and wont inhibit ai turn times, whereas the ifs might.

    I guess it's a for next loop like I miss so much from my old sinclair zx spectrum Basic.

    I have tweaked the code a bit more to share values correctly, but the "while" part is fine as shown.

    NEW BGR V 20150324! . . . . . . . .. . . .BGRIV_E

  8. #8
    Gorrrrrn's Avatar Citizen
    Join Date
    Jan 2007
    Location
    here
    Posts
    5,546

    Default Re: while end_while query

    Quote Originally Posted by Byg View Post
    .....

    I guess it's a for next loop like I miss so much from my old sinclair zx spectrum Basic.
    them woz the days, I started with ZX81 basic and ended up with QL Superbasic.

    Never been able to program anything since.

  9. #9
    Squid's Avatar Opifex
    Patrician Artifex Technical Staff

    Join Date
    Feb 2007
    Location
    Frozen waste lands of the north
    Posts
    17,751
    Blog Entries
    3

    Default Re: while end_while query

    As far as I'm aware event counters are either on or off (1 or 0) so your use of event counters is incorrect. All those counters you want to reach 50 should be regular counters and not event counters. Also you have no code to verify whether or not the script works and your event counters actually do get to 50 or not, you just verify that the mainbag counter gets reduced to 0 (not the same thing). Yet another thing, since this is presumably in the campaign script and not in a monitor the while statement will get executed immediately upon campaign start and not do anything since mainbag has not yet been set to 100. So the suggestion of putting the while in the monitor is a good one.
    Under the patronage of Roman_Man#3, Patron of Ishan
    Click for my tools and tutorials
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -----Albert Einstein

  10. #10
    Byg's Avatar Read The Manual
    Patrician

    Join Date
    Nov 2005
    Posts
    4,569

    Default Re: while end_while query

    Quote Originally Posted by Squid View Post
    As far as I'm aware event counters are either on or off (1 or 0) so your use of event counters is incorrect. All those counters you want to reach 50 should be regular counters and not event counters. Also you have no code to verify whether or not the script works and your event counters actually do get to 50 or not, you just verify that the mainbag counter gets reduced to 0 (not the same thing). Yet another thing, since this is presumably in the campaign script and not in a monitor the while statement will get executed immediately upon campaign start and not do anything since mainbag has not yet been set to 100. So the suggestion of putting the while in the monitor is a good one.
    No. I've used event counters for years, they can be any value.

    Regular counters are no good as I share this information with other files.

    The console command in the if statement should verify if the counters are working, should it not?

    I'll try putting the while in a monitor.

    NEW BGR V 20150324! . . . . . . . .. . . .BGRIV_E

  11. #11
    Byg's Avatar Read The Manual
    Patrician

    Join Date
    Nov 2005
    Posts
    4,569

    Default Re: while end_while query

    Success. All code as shown in my original script, but I simply moved the word "end_monitor" to the end. To me that seems an illogical format, but there you are. Now I have a number crunching system to help process some of the complex ideas for BGRV.
    Last edited by Byg; February 19, 2011 at 03:06 AM.

    NEW BGR V 20150324! . . . . . . . .. . . .BGRIV_E

  12. #12
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: while end_while query

    It appeared quite logical to me in the final layout.
    Code:
    Start of monitor
      Monitor's conditions (optional)
          start a loop until a condition is met
             do this until the loop's condition is met
          end the loop
       Monitor's commands (optional)
    End of monitor










  13. #13
    Byg's Avatar Read The Manual
    Patrician

    Join Date
    Nov 2005
    Posts
    4,569

    Default Re: while end_while query

    I don't see why the trigger has to be in the while loop though. That seems illogical when the value that is all the loop requires exists universally, if you know what I mean. I would find it logical if it simply monitored the event counter value.

    NEW BGR V 20150324! . . . . . . . .. . . .BGRIV_E

  14. #14
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: while end_while query

    It causes a loop that keeps repeating while the condition is true? Very interesting.

  15. #15
    Germanicu5's Avatar Will buy spare time...
    Join Date
    Feb 2009
    Location
    Not Zee Germany
    Posts
    2,101

    Default Re: while end_while query

    I never realised there were any doubts on how "while" loop worked, I've been using them on different occasions, here's an example of a script that manipulates king's purse (it used to be a part of Spoils of War mod, it's cool for economy-based operations).

    It runs continuously until each counter is decreased to "0" (counter set via some other monitor ofc), then it shuts.
    Spoiler Alert, click show to read: 
    monitor_event FactionTurnStart FactionType spain

    while I_CompareCounter purse_spain1 > 0
    increment_kings_purse spain -900
    inc_counter purse_spain1 -1
    end_while

    while I_CompareCounter purse_spain2 > 0
    increment_kings_purse spain -1100
    inc_counter purse_spain2 -1
    end_while
    end_monitor


    Regards
    I have no memory of this place.

  16. #16
    Byg's Avatar Read The Manual
    Patrician

    Join Date
    Nov 2005
    Posts
    4,569

    Default Re: while end_while query

    Well now we have had the pleasure of discovering something for ourselves without borrowing from others' work. It's a good thing you didn't get here earlier. Also now we have this thread at the top of the search list for "end_while" so it all turned out well.
    Last edited by Byg; February 19, 2011 at 02:57 PM.

    NEW BGR V 20150324! . . . . . . . .. . . .BGRIV_E

  17. #17
    Germanicu5's Avatar Will buy spare time...
    Join Date
    Feb 2009
    Location
    Not Zee Germany
    Posts
    2,101

    Default Re: while end_while query

    I'd rather save you some time if I saw the thread earlier, I just gave an example on how I've been using "while" loop. I assume posting some code here is for mutual benefit... and I'm a fan of BGR, so I'm happy whenever it gets more features . And I agree there's no better way of learning than trying it yourself.

    Edit: I just remembered gracul posted simple code containing "while" loop while we were having a discussion on economy mod): here

    Regards

    P.S. And "while" we're at it , maybe you'll find this info useful: "if" quotes can be put inside eachother (it decreases number of code that parser needs to process, again I have no idea whether it's been discussed before). An example would be:

    if I_EventCounter XXX > 0
    if I_EventCounter XXX = 1
    execute_code
    end_if
    if I_EventCounter XXX = 2
    execute_code
    end_if
    end_if
    Last edited by Germanicu5; February 19, 2011 at 03:35 PM.
    I have no memory of this place.

  18. #18
    Byg's Avatar Read The Manual
    Patrician

    Join Date
    Nov 2005
    Posts
    4,569

    Default Re: while end_while query

    Funny thing is, I did actually use "while" 4 or 5 years ago in BGRIII and it had the remarkable effect of reducing the turn time of my notoriously long settlement script by about 90%. I think it was Taiji who later warned me that some scripts were not working. It turned out that my fast "while" loop method sped things up by disabling all the campaign scripts, except mine.

    NEW BGR V 20150324! . . . . . . . .. . . .BGRIV_E

  19. #19
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: while end_while query

    I wonder how many running monitors the game can cope with, if it's an issue. Just using waits raises the question of how many monitors can be executed concurrently, but with whiles, since there is active processing of a loop, I figure any issue might be further highlighted, or more likely.

    It would be interesting to know what script conflicted with, or blocked execution of, which other scripts in your experience, Byg. Like were they scripts firing using the same event? Or event+conditions? My guess would be a similar monitor being unable to run until the 'while' finishes, or something like that. I'm hoping/guessing that not all monitors get blocked when a while is in operation.

    Also it might well be possible to combine the scripts using an if statement, and so maintain the while process without blocking anything. Not that it matters by now, I guess.
    Last edited by Taiji; February 19, 2011 at 06:49 PM.

  20. #20
    Byg's Avatar Read The Manual
    Patrician

    Join Date
    Nov 2005
    Posts
    4,569

    Default Re: while end_while query

    Well I assume the 1st post example halts everything whilst it runs. At least I could not click on another unit until after.

    The "while" that excluded all other people's scripts did so because I wrapped my entire script in one. Incidentally, the lesson learned there was that if you ever want your script to run faster in a multimod environment, just delete everyone else's stuff.

    NEW BGR V 20150324! . . . . . . . .. . . .BGRIV_E

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •