Script Assistance

Post » Tue May 17, 2011 10:48 am

I have an object script that runs with a menu. It is failing, as near as I can tell with liberal use of ShowMessage statements, at this point when iItem is greater than 1. If iItem is just one, it works fine and adds an item to the player's inventory; subsequent runs cause it to crash. Is there something I'm neglecting to do? Is there some other way to clear the oItem variable maybe? I'm a complete loss. Oh, this portion is part of a Begin GameMode block if that makes any difference.

short iItem = A variable that gets filled earlier in the script, from 0 to N
ref oItem = Used only here; it fails if iItem is > 1 whether I have the set oItem to 0 or not.
Label 4
if iItems > 0
set rndNum to GetRandomPercent
set oItem to 0
set oItem to ListGetNthForm yapmItemList rndNum
Player.AddItem oItem 1
set iItems to iItems - 1
GoTo 4
endif

Thanks!
Rig
User avatar
OJY
 
Posts: 3462
Joined: Wed May 30, 2007 3:11 pm

Post » Tue May 17, 2011 6:12 am

short iItem = A variable that gets filled earlier in the script, from 0 to N
ref oItem = Used only here; it fails if iItem is > 1 whether I have the set oItem to 0 or not.
Label 4
if iItems > 0
set rndNum to GetRandomPercent
set oItem to 0
set oItem to ListGetNthForm yapmItemList rndNum
Player.AddItem oItem 1
set iItems to iItems - 1
GoTo 4
endif

Thanks!
Rig


1. Is it iItem or iItems? you have both listed.
2. Short variables cannot hold hex values such as N as they function the same as INT variables. They also cannot hold alphanumeric letters like a FOSE string variable can. You'll need to find a workaround, or use numbers only and specify the results for each one.
3. GetRandomPercent returns numbers between 0 and 99. It will fail if your list doesn't have 100 items in it or a number higher than the last list entry is chosen. To get RND numbers between a minimum and maximum use the formula:
set VARIABLE to min + GetRandomPercent * (max-min) / 99
User avatar
Nancy RIP
 
Posts: 3519
Joined: Mon Jan 29, 2007 5:42 am

Post » Tue May 17, 2011 3:40 am

1. lol Yeah, you're right; it is iItems which is defined as a short. oItem is defined as a reference. I know, crappy variable naming on my part; I wasn't thinking about unitl I read your post. :)
2. I'll have to check how I'm doing this, but I think it's correct. oItem is a reference variable, so returning a value from the List should be ok, right?
3. Sorry, I didn't clarify. The List (yapmItemList) has 100 items in it. That was the first thing I checked because I thought that might be the case.

Hmm, I still have no idea how to make it work. Thanks anyway,
Rig

1. Is it iItem or iItems? you have both listed.
2. Short variables cannot hold hex values such as N as they function the same as INT variables. They also cannot hold alphanumeric letters like a FOSE string variable can. You'll need to find a workaround, or use numbers only and specify the results for each one.
3. GetRandomPercent returns numbers between 0 and 99. It will fail if your list doesn't have 100 items in it or a number higher than the last list entry is chosen. To get RND numbers between a minimum and maximum use the formula:
set VARIABLE to min + GetRandomPercent * (max-min) / 99

User avatar
Rik Douglas
 
Posts: 3385
Joined: Sat Jul 07, 2007 1:40 pm

Post » Tue May 17, 2011 10:59 am

2. I'll have to check how I'm doing this, but I think it's correct. oItem is a reference variable, so returning a value from the List should be ok, right?

Not oItem, iItems.. you have it listed as 'short iItems', then you say "from 0 to N"... Either I'm misunderstanding what you mean by that, or you're trying to assign incorrect hex(?) values to a short variable.. Where does "N" come from?
User avatar
James Wilson
 
Posts: 3457
Joined: Mon Nov 12, 2007 12:51 pm

Post » Tue May 17, 2011 10:59 am

Ah, that! Sorry, that was my way of explaining what those variables are used for.

It seems to be a conflict with an existing mod; I tried removing several of them and ran it again, and it appears to be working. Now, I just need to figure out which mod it is conflicting with and why.

Rig

Not oItem, iItems.. you have it listed as 'short iItems', then you say "from 0 to N"... Either I'm misunderstanding what you mean by that, or you're trying to assign incorrect hex(?) values to a short variable.. Where does "N" come from?

User avatar
:)Colleenn
 
Posts: 3461
Joined: Thu Aug 31, 2006 9:03 am

Post » Tue May 17, 2011 11:28 am

Ah, that! Sorry, that was my way of explaining what those variables are used for.

It seems to be a conflict with an existing mod;

Ahhhh ok. That kind of spun me for a few lol.
Mod conflict.. yeah that's more doable. I've never had to do it, but I'm pretty sure you can run your mod and the offending one (when you pin down which one it is) through FO3Edit and it'll point out any conflicts. Manually, you can check your form names and script variable names to see if one of them is used by the other mod.
User avatar
Queen Bitch
 
Posts: 3312
Joined: Fri Dec 15, 2006 2:43 pm


Return to Fallout 3