Jump to content

How do I make an un-nest an If statment?


Akatosh2903

Recommended Posts

I can't save this script because it is nested, how do I remove the nest?

 

ScriptName 0AutoFireModScript

int WeaponHealth1
begin
if player.getEquipped == WeapChinesePistol
begin OnEquip player
set WeaponHealth1 to GetWeaponHealthPerc
player.RemoveItem WeapChinesePistol 1
player.AddItem 0MauserFullAuto 1
player.EquipItem 0MauserFullAuto 0 1
player.SetWeaponHealthPerc to WeaponHealth1
end
else
 ShowMessage 0WeapModWontWork
endif
end


int WeaponHealth2
begin
if player.getEquipped == 0MauserFullAuto
begin OnEquip player
 set WeaponHealth2 to GetWeaponHealthPerc2
 player.RemoveItem 0MauserFullAuto 1
 player.AddItem WeapChinesePistol 1
 player.EquipItem WeapChinesePistol
 player.SetWeaponHealthPerc to WeaponHealth2
end
endif
end

Edited by Akatosh2903
Link to comment
Share on other sites

I am far from an advanced scripter but I do know that it should look more like this:

 

ScriptName 0AutoFireModScript

int WeaponHealth1
int WeaponHealth2

Begin OnEquip player

    if player.getEquipped == WeapChinesePistol
         set WeaponHealth1 to GetWeaponHealthPerc
         player.RemoveItem WeapChinesePistol 1
         player.AddItem 0MauserFullAuto 1
         player.EquipItem 0MauserFullAuto 0 1
         player.SetWeaponHealthPerc to WeaponHealth1
    else
         ShowMessage 0WeapModWontWork
    endif

    if player.getEquipped == 0MauserFullAuto
         set WeaponHealth2 to GetWeaponHealthPerc2
         player.RemoveItem 0MauserFullAuto 1
         player.AddItem WeapChinesePistol 1
         player.EquipItem WeapChinesePistol
         player.SetWeaponHealthPerc to WeaponHealth2
    endif

End

 

Like I said my scripting syntax is not terribly fluent but as far as structure this should be closer to what your looking for.

Link to comment
Share on other sites

The compiler shouldn't reject nested If statements, I've used a fair few before. It just means you have IF statements inside other IF statements, like this

 

if light switch on

if bulb in socket

bulb lights up

endif

endif

 

it looks like there's a few problems with the syntax of the script that might stop it from compiling though. I'm not sure but I don't think you can put a begin block inside an IF statement, or have a begin block without a condition (so just writing Begin on a line might not work, whereas writing Begin OnActivate, or Begin OnEquip should, because the compiler needs to know when to begin).

 

I'd say ElderMalaclypse's code should work apart from the == in the getequipped lines.

You could try this though:

(sorry, had a go at editing the code before I saw yours, then posted accidentally before I'd finished, anyway hope it helps at least)

 

ScriptName 0AutoFireModScript

int WeaponHealth1
int WeaponHealth2

begin OnEquip player

if player.getEquipped WeapChinesePistol
set WeaponHealth1 to GetWeaponHealthPerc
player.RemoveItem WeapChinesePistol 1
player.AddItem 0MauserFullAuto 1
player.EquipItem 0MauserFullAuto 0 1
player.SetWeaponHealthPerc to WeaponHealth1

elseif player.getEquipped 0MauserFullAuto

 set WeaponHealth2 to GetWeaponHealthPerc2
 player.RemoveItem 0MauserFullAuto 1
 player.AddItem WeapChinesePistol 1
 player.EquipItem WeapChinesePistol
 player.SetWeaponHealthPerc to WeaponHealth2

else
 ShowMessage 0WeapModWontWork
endif

end

Edited by caramellcube
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...