Page 1 of 6 123 ... LastLast
Results 1 to 10 of 60

Thread: Schripting Advice (Tutorial)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Schripting Advice (Tutorial)

    In my short time with MOHAA I have realized one thing very quickly, the level scripts are a total mess, especially the global scripts.
    The custom scripts made by users are much better but still to messy...

    I might not know much about MOHAA as a game, but I am pretty familiar with the Morpheus Scripting system.
    Even if the version used in MOHAA is quite different, I know how to write readable code.
    So I did write a sort of Advise Tutorial Document thingy.

    It is not quite complete yet, as it is missing one section and I will probably expand it a little.
    Non the less, you feedback and input is welcome
    Last edited by chrissstrahl; July 18th, 2018 at 04:14 PM.

  2. #2
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,269

    Default

    A few comments on a quick look over I did at work.

    I agree with the brackets in most parts, but at the start of the thread/label is IMO worse then leaving them out, same as using brackets for grouping if you need to group then do it in separate threads.
    Also certain 1 line if statements look better without brackets, but anything too complicated then brackets are a must.

    Ewww GOTOs I agree to never ever ever ever use them lol.

    Also mohaa has a way to wait for players to spawn it is called
    level waittill playerspawn
    Which is more useful then a while loop checking,

    I will look more over it when I get home, but nice work so far from what I could read on my phone

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  3. #3

    Default

    Thanks, that is good input, I will think about making adjustments.
    Especially with the grouping, I also don't really feel it is right

    The problem with making brackets optional will leave room for leaving them completely again, which is why I don't make them optional.
    Maybe a one line alternative would be good to offer, something like:
    PHP Code:
    if(1) {...} 
    Using brackets with the function is a good thing, maybe as a alternative it could be done like this:
    PHP Code:
    main:
    {
    ...
    }
    end 
    collapsed would then look like (not as pretty but still okay):
    PHP Code:
    main:
    {
    end 
    I will look into level waittill playerspawn, I am not sure it it can be called in multiple separate threads, because I think I had some issues with it.
    But I will have to do some more tests. But in general I would agree that it is better using any other means.

    I try to get to inspire to a better scripting style, and I think leaving the brackets out of the functions is a mistake, especially if your text editor also highlights the brackets.
    That can help to quickly find where your function really ends, besides making it easy to collapse.

  4. #4
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    Nice guide
    I remember playerspawn had some catch to it.
    Personally, I prefer initial curly bracket to occupy a line itself
    Indentation is everything, I could not use brackets for a function decl. if indentation was done correctly.
    It'd also fix the single statement "if" issue.
    In fact, I think most mods do that.
    BTW, Some great modders used to semicolon-end every line back in the day iirc

  5. #5

    Default

    Thanks.
    I also prefer the brackets in a single line for functions, but from what I have seen in Mohaa scripts get big and messy fast, so I was thinking if functions are collapsed it should look simple and minimalistic.
    I am having a hard time not using semicolon at the end, but if I do the scripts don't work any more.
    Maybe if you remember what catch exactly playerspawn has, that would help

  6. #6

    Default

    Nice work. I don't think I'll use brackets for the methods and I never have an issue with entity attributes but generally speaking it's a good guide.

    I've experimented with my styles recently and find myself yes thinking about what other people will prefer but also what seems more readable to myself, which is ultimately more important in a way as I'm making them. I guess it's a subtle balance that is hard to be perfect.

    I also changed up my practices recently to see what is better. For example, what opinions do you guys have on deleting threads you no longer need as opposed to using global scope flags? In my first test_bocage map I had many level.flags["something"] variables for this purpose, but in the current map I'm scripting I'm leaning more towards declaring the thread and killing it when no longer needed...

    e.g.

    Code:
    //---------------------------------------------------------------//
    //	Mocking gunfire			  				    //							
    //---------------------------------------------------------------//
    MockMGFire:
    
    	level.mockFireThread = local
    
    	wait 3
    
    	for (local.i = 1; local.i <= 4; local.i++)	// *!* send out four bursts to mock player
    	{
    		local.randomint = randomint (29) + 1
    
    		if (local.randomint <= 10) 				// *!* pick corpse
    		{				
    			$mg42_nest setAimTarget $mgtarget[1]
    		}
    		else if (local.randomint <= 20 && local.randomint > 10)
    		{
    			$mg42_nest setAimTarget $mgtarget[2]
    		}
    		else
    		{
    			$mg42_nest setAimTarget $mgtarget[3]
    		}
    
    		wait .1
    
    		$mg42_nest startFiring
    		//$mg42_nest.isFiring = 1 
    
    		wait (randomfloat (3) + 1)
    
    		$mg42_nest stopFiring
    		//$mg42_nest.isFiring = 0
    
    		wait (randomfloat (2) + 1)
    	}
    end
    So, you can then stop the instructions immediately by:

    Code:
    	if (level.mockFireThread)
    		level.mockFireThread delete
    Instead of using flags and if statements in several locations in your method. Obviously it isn't for every situation, but I find it neater.

    Oh, and about the global scripts, I find Mackey McCandlish's code the most untidy, especially in his SP level scripts. But I believe it was hastily done in places so I can't fault them too much. Steve Fukuda and Benson Russell scripts are usually better, but I think they scripted a lot of the original E3 stuff so had more time on those levels.

    P.S. you used 'rabbit' instead of 'habit' in one place which made me giggle
    Last edited by 1337Smithy; July 10th, 2018 at 02:39 AM.

  7. #7

    Default

    Thanks.
    I understand why you would not want the brackets in the function, how ever if you did ever take a look into global/friendly.scr that script would really do good by these brackets, or more use of brackets to begin with.

    You need to be careful about deleting threads, if you are making a function call with parameters inside that function you are terminating, it can result in a stack underflow error, probably very hard to trace in this script language.
    But it is nice to know that you can actually delete (or remove) threads. I know of killthread, but I have not checked if it is available in this version.

    I can agree that it is better in most cases to handle the stuff in threads, and the threads them self, but it is also more advanced scripting and probably not easy to get into for most people.

    And Mackey McCandlish's code is the worst I have ever seen.
    I'll go now find the rabbit...
    Last edited by chrissstrahl; July 9th, 2018 at 12:53 PM.

  8. #8

    Default

    I have made a few adjustments based on the input from you guys.
    But I have still not written the thread/functions stuff, I think I will take a little more time there to make sure the advantages of using threads can be properly understood.
    But I have added entities.

    Let me know if you think that some areas might need more or less attention or should be changed more.
    Last edited by chrissstrahl; July 10th, 2018 at 03:24 PM.

  9. #9
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    I feel silly asking this, but does MOHAA scripting support a try{catch{}}?
    I know programming languages and even command line like powershell use it.

    I haven't seen it used in MOH scripting before, so I assume it's not supported, but if it is supported, I think it would be excellent to start seeing it used because it can potentially catch a lot of issues before causing errors such as memory leaks, infinite loops, and crashes.

    As far as functions/methods go I prefer formatting on new lines for brackets
    example


    func HelloWorld()
    {
    printf("Comment allez vous");
    printf("Co slychac syneczku");
    printf("Bienvenido");
    }

  10. #10

    Default

    Thanks, chrissstrahl. I'll take a look later.

    James, funnily enough I was going to attempt a try catch as I've seen it referenced in official documentation for the SDK. I wonder if it was added for Spearhead. I'll probably try tomorrow
    Last edited by 1337Smithy; July 9th, 2018 at 04:39 PM.

Posting Permissions

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