Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Morpheus and IF

  1. #1

    Default Morpheus and IF

    Am I an idiot or does Morpheus just not allow consecutive IF statements?

    "Bad Practice" aside... This refuses to work:
    Code:
    IF (something1 == somethingA) { do this }
    IF (something2 == somethingB) { do this }
    I'm aware of switches, ELSE and ELSE IF work as expected, etc. Just not IF followed by IF.

    Am I missing something?

  2. #2
    Developer Todesengel's Avatar
    Join Date
    Dec 2013
    Location
    St. Louis, Missouri, USA
    Posts
    276

    Default

    that construct is valid. Can you post actual code?

  3. #3

    Default

    'IF' all caps won't work. Try lowercase.

  4. #4

    Default

    Here is an example scenario.

    What I expect to happen:
    (first pass)
    IF #1 = True
    IF #2 = False
    ELSE = True
    (second pass)
    IF #1 = False
    IF #2 = True
    break


    main:

    if (level.example1)
    end
    level.example1 = 1


    local.var = 0
    while(1)

    if (local.var == 0) {
    wait 1
    stuffsrv ("say First IF statement TRUE.")
    }


    if (local.var == 1) {
    wait 1
    stuffsrv ("say Second IF statement TRUE.")
    break
    }
    else {
    wait 1
    stuffsrv ("say ELSE statement TRUE.")
    local.var = 1
    }
    end


    With two IF's next to each other the script breaks. Perhaps I've been spoiled in the past with good languages making up for bad coding

  5. #5
    Developer Todesengel's Avatar
    Join Date
    Dec 2013
    Location
    St. Louis, Missouri, USA
    Posts
    276

    Default

    missing initiator { after while condition.

  6. #6

    Default

    and end }

  7. #7

  8. #8
    Developer Todesengel's Avatar
    Join Date
    Dec 2013
    Location
    St. Louis, Missouri, USA
    Posts
    276

    Default

    watch your braces. Probably something more like....

    Code:
    main:
    
    if (level.example1) end
    level.example1 = 1
    
    local.var = 0
    while(1) {
    
    	if (local.var == 0) {
    		wait 1
    		stuffsrv ("say First IF statement TRUE.")
    	}
    
    	if (local.var == 1) {
    		wait 1
    		stuffsrv ("say Second IF statement TRUE.")
    		break
    	} else {
    		wait 1
    		stuffsrv ("say ELSE statement TRUE.")
    		local.var = 1
    	}
    }
    
    end
    Last edited by Todesengel; November 16th, 2019 at 11:04 AM. Reason: no coffee

  9. #9

    Default

    BuriedAlive, if you want it in a while you'll also need some wait of some sort in there, to stop crashes due to infinite loop protection .

  10. #10
    Developer Todesengel's Avatar
    Join Date
    Dec 2013
    Location
    St. Louis, Missouri, USA
    Posts
    276

    Default

    And generally, switch/case yields better performance than a set of ifs, so I'd suggest a case (local.var) and switch 0: switch 1: and default:

Posting Permissions

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