Jump to content

WeapForm.GetBaseDamage() type mismatch while assigning to a int (cast missing or types unrelated)


irswat

Recommended Posts

any idea why the compiler is throwing this error: type mismatch while assigning to a int (cast missing or types unrelated)


			if MatchingWords==LengthOfCMDItem
				tempWeap=WeaponFormList.GetAt(CompareArrayCounter1)
				tempWeapBaseDMG=tempWeap.GetBaseDamage()
				if PlayerREF.GetItemCount(tempWeap)>=1
					debug.trace("Efficiency exception detected.")
					;perfect match found
					FormToReturn=tempWeap
					break=true
				endif
			endif

 

Link to comment
Share on other sites

It could maybe be of help to know which line the error was on. There does not seem to be anything totally wrong in that one. Judging by the wiki examples, it might work a bit like this:

FormList property WeapFormList auto

function DamageTest(int Index)
    Weapon TempWeap = WeapFormList.GetAt(Index) as Weapon
    int TempDamage = TempWeap.GetBaseDamage()
    Debug.MessageBox("WeapList[" + Index + "] = " + TempWeap + " (dmg " + TempDamage +")")
endfunction

At least according to the GetBaseDamage page I think (in a hurry at the moment, so I might have read something wrong, too. :blush:

 

http://www.creationkit.com/index.php?title=GetBaseDamage_-_Weapon

 

Hopefully that helps a bit.

Edited by Contrathetix
Link to comment
Share on other sites

Sorry. Error is on int TempDamage = TempWeap.GetBaseDamage(): type mismatch while assigning to a int (cast missing or types unrelated)

 

tempWeap is declared as a form. I wonder if something like this would work:

TempDMG=tempWeap as Weapon.GetBaseDamage()

 

I'll try it after work. thanks guys.

Link to comment
Share on other sites

The issue seems to be with the type of the weapon variable set to Form. I finally got home, and tested it (out of curiosity), and using a "Form TempWeap" instead of "Weapon TempWeap" causes the error when compiling. However I use SublimePapyrus myself so it highlights the missing function GetBaseDamage when I type it in and try to use it on a Form (instead of a Weapon).

 

As in, this causes an error (obviously, Form does not have that function):

Form TempWeapon = WeaponList.GetAt(Index) ; <-- GetAt returns a Form
int TempDamage = TempWeap.GetBaseDamage() ; <-- Form Script has no "GetBaseDamage" function

This one also causes an error (missing cast, GetAt returns a Form):

Weapon TempWeapon = WeapList.GetAt(Index) ; <-- GetAt returns a Form

However this works fine:

Form TempWeapon = WeaponList.GetAt(Index) ; <-- getAt returns a Form
int TempDamage = (TempWeap as Weapon).GetBaseDamage() ; <-- calling GetBaseDamage on Weapon (the cast result)

And this one also works fine:

Weapon TempWeapon = WeaponList.GetAt(Index) as Weapon ; <-- get the Form as a Weapon straight away
int TempDamage = TempWeapon.GetBaseDamage() ; <-- TempWeapon is already a Weapon

If you want to do lots and lots of Papyrus scripting, and use Sublime Text as your text editor (I use Sublime Text 3), SublimePapyrus by mrpwn is a great utility. Definitely recommended. It checks your scripts on the fly, offers all sorts of completions when typing and also offers the ability to import sources from here and there. Definitely invaluable, and actually makes scripting fun, too. Here --> http://www.nexusmods.com/skyrim/mods/60810

 

Hopefully that helps a bit. :thumbsup:

 

Edit: Still cannot type... :facepalm:

Edited by Contrathetix
Link to comment
Share on other sites

  • Recently Browsing   0 members

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