Page 1 of 1

Script was working now it isn't...Bad Token error

Posted: Sun Aug 28, 2005 2:43 pm
by Waylander76
Below is my script which was working and now it isn't.
It throws up the following error in the qconsole.log

TOKEN_IDENTIFIER:
goto

goto flyby (maps/obj/obj_pegasus.scr, 88)
^

This part was working fine I only added the axis_boat1 thread and saved the script and now I get the above error.
before it was all working perfectly.

Any ideas anyone?

TIA

Here's my script in full....

Code: Select all

// ARCHITECTURE: =VFor=Waylander
// SCRIPTING: =VFor=Waylander with help from those at .MAp.Net

main:

setcvar "g_obj_alliedtext1" "Destroy the Flak88"
setcvar "g_obj_alliedtext2" ""
setcvar "g_obj_alliedtext3" "" 
setcvar "g_obj_axistext1" "Defend the Flak88"
setcvar "g_obj_axistext2" ""
setcvar "g_obj_axistext3" " Bridge Model By Atomic"
setcvar "g_scoreboardpic" "obj_pegasus"

level waittill prespawn

exec global/DMprecache.scr

	//***Flyby Planes

	exec global/bomber.scr
	thread flyby
	thread boat_prep
	thread boat_prep2
	thread boat_prep3
	thread boat_prep4

level.script = maps/obj/obj_pegasus.scr
level.music = obj_team1
exec global/ambient.scr
thread global/exploder.scr::main // Initialize the exploder subsystem

level waittill spawn

        $world farplane_cull 0 
	$world farplane 6000
        $world farplane_color (0.675 0.663 0.651)



level.defusing_team = "axis" // Axis like the bombs unplanted
level.planting_team = "allies" // Allies will try to plant the bombs
level.targets_to_destroy = 1 // Number of targets in this map
level.bomb_damage = 200 // Default damage of the bomb
level.bomb_explosion_radius = 2048 // Default radius of bomb blast

// Set the parameters for round based match
level.dmrespawning = 0 // 1 or 0 (0=no respawn)
level.dmroundlimit = 5 // round time limit in minutes
level.clockside = axis // set to axis, allies, kills, or draw

level waittill roundstart // Comment out this line using '//' before it to be able to set the bomb when alone on the map ( just for testing )

		thread flyby
		thread axis_perimeter

$panel_bomb thread global/obj_dm.scr::bomb_thinker // "panel_bomb" is the targetname set on the bomb in MOHRadiant
thread allies_win_bomb // Start the win check thread for allies
$panel_bomb thread axis_win_timer // Start the win check thread for axis
end // end of main

// Allied victory test

allies_win_bomb:
while(level.targets_destroyed < level.targets_to_destroy) // While undestroyed objectives left
waitframe // chill out
teamwin allies // No objectives left allies win
end // end allied victory test

// Axis victory test

axis_win_timer:
level waittill axiswin // At the end Axis win
end // end axis victory test

flyby:

	//***random flyby of plane
	wait 1.0
        thread global/bomber.scr::bomb 1
	thread global/bomber.scr::bomb 2
	thread global/bomber.scr::bomb 3
	thread global/bomber.scr::bomb 4
	thread global/bomber.scr::bomb 5
	thread global/bomber.scr::bomb 6
	thread global/bomber.scr::bomb 7
	thread global/bomber.scr::bomb 8
	wait (randomint(180) + 60
goto flyby

end

boat_prep:

	$row_boat1 time 15
	goto boat_move
end

boat_prep2:

	$row_boat2 time 15
	goto boat_move2
end

boat_prep3:

	$row_boat3 time 15
	goto boat_move3

end


boat_prep4:

	$axis_boat1 time 15
	goto axisboat_move1

end


boat_move:

$boat_trigger1 waittill trigger
//$row_boat1 moveto $boat1_wap1
//$row_boat1 waitmove 
$row_boat1 moveto $boat1_wap2
$row_boat1 waitmove 

goto boat_move

end

boat_move2:

$boat_trigger2 waittill trigger
//$row_boat2 moveto $boat2_wap1
//$row_boat2 waitmove 
$row_boat2 moveto $boat2_wap2
$row_boat2 waitmove 

goto boat_move2

end

boat_move3:

$boat_trigger3 waittill trigger
//$row_boat3 moveto $boat3_wap1
//$row_boat3 waitmove 
$row_boat3 moveto $boat3_wap2
$row_boat3 waitmove 

goto boat_move3

end

axisboat_move1:

$axis_boat_trigger waittill trigger
$axis_boat1 moveto $axis_wp2
$axis_boat1 waitmove 

goto axisboat_move1

end

axis_perimeter:

  
    local.player = parm.other
    if ( (local.player.dmteam != "allies") || (level.axisperimeter_breached == 1) )
      end
      
    iprintlnbold "The Allies have breached the perimeter!"
    level.axisperimeter_breached = 1
end


kaboom_water:

	exec global/exploder.scr::explode 4 // water plume
      
end

kaboom_water1:

	exec global/exploder.scr::explode 4 // water plume
	

end

Posted: Sun Aug 28, 2005 2:56 pm
by jv_map
wait (randomint(180) + 60

should be

wait (randomint 180 + 60)

And besides, goto is evil :wink:

Posted: Sun Aug 28, 2005 4:48 pm
by Waylander76
LOL! thanks for that...working order has been restored! :)

Why exactly is goto evil? :shock:

Posted: Sun Aug 28, 2005 6:12 pm
by ViPER
goto can work but Its better to end your threads.

replace it with end and use a while loop.

goto

Posted: Sun Aug 28, 2005 6:50 pm
by tltrude
The goto line can also be replaced with:

thread flyby

Posted: Sun Aug 28, 2005 7:05 pm
by lizardkid
goto is considered extremely sloppy coding in almost every language nowadays. loops are better design anyway. You could improve this thread for instance...

Code: Select all

flyby: 

   //***random flyby of plane 
   wait 1.0 
        thread global/bomber.scr::bomb 1 
   thread global/bomber.scr::bomb 2 
   thread global/bomber.scr::bomb 3 
   thread global/bomber.scr::bomb 4 
   thread global/bomber.scr::bomb 5 
   thread global/bomber.scr::bomb 6 
   thread global/bomber.scr::bomb 7 
   thread global/bomber.scr::bomb 8 
   wait (randomint(180) + 60 
goto flyby 

end
by doing this

Code: Select all

flyby: 
//***random flyby of plane 

while(1)
{
   for(local.z = 8; local.z > 0; local.z--)
   {
         thread global/bomber.scr::bomb local.z
   }
   wait (randomint(180) + 61) 
}
end

Posted: Thu Sep 01, 2005 10:17 am
by Waylander76
As scripting is new to me I wanted to keep it basic so I could actually
understand what bits were doing what!! :D

This site has been invaluable as a source for learning things so I'd like to say thanks to everyone as it has been very helpful! :D

Posted: Thu Sep 01, 2005 10:38 pm
by lizardkid
As scripting is new to me I wanted to keep it basic so I could actually
understand what bits were doing what!!
No there's nothing wrong with understanding things, this is just a more widely accepted way of doing things ;)

and now you know :)

Posted: Thu Sep 01, 2005 11:17 pm
by Bjarne BZR
Waylander76 wrote:Why exactly is goto evil? :shock:
Because it makes code hard to read and easy to crash.

As an example:
In your code, what you are doing is essentially looping. It is a lot moore obvious that you are looping if you use... say... a loop :)

Goto gets dangerous when.. say you write "goto place1" and that was a mistake, you were supposed to goto place2... the code looks the same, and the jump to place2 is still legal ( if it exists ), and there are noe clues as to how the execution flows, you need to look for some label somewhere.

Basically most code is essentially sequential. By introducin goto:s, all bets are off: you can end up anywhere when least expecting to.

I've only heard of one situation where a goto is actually making code better or easier to read: aborting multiple nested loops.

Say you are looping through the pieces of a Rubics qube:

Code: Select all

for(local.x = 0; local.x<3; local.x++)
{
	for(local.y = 0; local.y<3; local.y++)
	{
		for(local.z = 0; local.z<3; local.z++)
		{
			// For some reason I
			// want to break the
			// loop now before
			// all parts are processed.

			if(local.some_reason)
			{
				goto abort_rubic_search
			}
		}
	}
}
abort_rubic_search:
Aborting single loops are usually done with the call break or continue ( not 100% sure MOHAA has those in script however ).

The rule I'd suggest is:
* dont use goto unless there are no other ways to do it.
* if you use goto, never jump backwards in the code. Really hard to follow.
* use it if you want to confuse youself and others ( If this is the case I would also suggest creating labels at execution time, using random numbers and executing them at random times. Calling functions that delete stuff something like "create" can also be a tip. Oh, and name labels stuff like "wwoOot" and "H4X0r_cRAXoR" and other really informative names ). :twisted:

Posted: Fri Sep 02, 2005 3:33 am
by lizardkid
break is indeed in MOHscript (think of switch), continue i've never found a use for in any language so i've never tried it in MOH.

Posted: Fri Sep 02, 2005 6:41 am
by jv_map
break and continue work great in mohaa scripting.

P.S. tltrude replacing the goto with a thread call is even worse :wink: basically you're calling in a seperate process to execute each loop... having everything in a simple while loop is much more efficient (hence faster).