How stupid am I?

Post » Sat May 01, 2010 5:45 am

OK, I have no background in coding, so I usually work through trial and error.

But I have a piece of code that is confusing the heck out of me and would appreciate someone with far greater understanding helping me to become less stupid.

In porting the BOE recoil effect to NV, I could not get it to function properly for the longest time. Until I added an endif statement that by my reckoning should not be needed. Then the code functioned perfectly.

Here is the code which is attached to a token.

SCN xMoRecoilEffectshort ammocountshort Setupfloat fRisefloat fAnglefloat Kickref rCurrentGunref rCurrentAmmoref rNewAmmoBEGIN Gamemode	IF Setup == 0		Set rCurrentGun to player.getequippedobject 5		Set rCurrentAmmo to GetPlayerCurrentAmmo		Set AmmoCount to player.GetItemCount rCurrentAmmo;		PrintToConsole "Current Weapon is %n" rCurrentGun;		PrintToConsole "Current Ammo is %n" rCurrentAmmo		Set Setup to 1	EndIF	EndIF											; <---- script fails to execute without this additional EndIF ????	IF AmmoCount > (player.getitemcount rCurrentAmmo)		Set Kick to xMoGuns.Kick		IF IsControlPressed 6			Set Kick to (Kick*0.75)		EndIF		IF player.IsSneaking			Set Kick to (Kick*0.75)		EndIF		set fAngle to player.getangle x - Kick 		IF ( fAngle>=-89 && fAngle<=89 )			player.setangle x fAngle		EndIF		set fRise to ((getrandompercent - 50)/150)*Kick		set fAngle to player.getangle z - fRise		player.setangle z fAngle;		PrintToConsole "Kick applied is %.4f" kick;		PrintToConsole "Ammo Count is %.0f" AmmoCount	EndIF	Set AmmoCount to player.GetItemCount rCurrentAmmo	Set rNewAmmo to GetPlayerCurrentAmmo	IF ( rCurrentAmmo != rNewAmmo);	IF ( rCurrentAmmo != GetPlayerCurrentAmmo)		Set Setup to 0	EndIF	IF ( rCurrentGun != player.getequippedobject 5 )		player.removeitem xMoRecoilToken 1 1	EndIFEND

User avatar
M!KkI
 
Posts: 3401
Joined: Sun Jul 16, 2006 7:50 am

Post » Sat May 01, 2010 5:21 am

You've got an uneven number of ifs/endifs in the last handful of lines. Your extra endif means the counts match up, although it's in the wrong place, so I'd expect the script to be somewhat mangled in execution.
User avatar
Tamara Dost
 
Posts: 3445
Joined: Mon Mar 12, 2007 12:20 pm

Post » Sat May 01, 2010 4:46 pm

Yeah ,but there's a comment in front of one of the IF's, which evens them out.

;	IF ( rCurrentAmmo != GetPlayerCurrentAmmo)

User avatar
marina
 
Posts: 3401
Joined: Tue Mar 13, 2007 10:02 pm

Post » Sat May 01, 2010 4:03 am

The script is still contains debug stuff. The last section is my attempt to remove the need for a superfluous rNewAmmo variable.

GetPlayerCurrentAmmo is a new function in the NVSE beta release. It works but I think it may be the proximate cause of the weirdness.
User avatar
Janette Segura
 
Posts: 3512
Joined: Wed Aug 22, 2007 12:36 am

Post » Sat May 01, 2010 6:16 am

I'm blind, apparently.
Are you actually getting the kick behaviour when that second endif is in? A few times I've had apparently incorrect functions seem to make scripts work, when what they were actually doing was stopping their execution early each frame before they got to the code that made them crash.
User avatar
Marcia Renton
 
Posts: 3563
Joined: Fri Jan 26, 2007 5:15 am

Post » Sat May 01, 2010 4:10 am

Script works great exactly as I posted.

Without the second endif, script does nothing and even the printc's (uncommented) in the setup block do nada.

If anyone wants to download a http://www.mediafire.com/download.php?3tjmb7tjvubhcm5 to have a look, feel free.
User avatar
Pants
 
Posts: 3440
Joined: Tue Jun 27, 2006 4:34 am


Return to Fallout: New Vegas