Deleted4782829User Posted April 27, 2014 Share Posted April 27, 2014 I'm working on a script that needs to find one specific form in a cell and then make it a objectreference. While !Stop && !(Target.GetBaseObject() == OldBaseObject) Target = Game.FindRandomReferenceOfTypeFromRef(OldBaseObject, CenterMarker, 51200) as ObjectReference if !Target Stop = True endif EndWhile ObjectReference Property Target Auto ObjectReference Property CenterMarker Auto Form OldBaseObjectthis is a small part of the bigger script, but this is the part i'm having trouble with, it can find the objecttype, but the "!(Target.GetBaseObject() == OldBaseObject)" doesn't seem to work at allit will look for the type of object that "OldBaseObject" is pointing to, but not the specific baseobject/form. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 27, 2014 Share Posted April 27, 2014 What I noticed was that OldBaseObject was defined as a form but had no value. Target was given a property value but you were trying to overwrite it. So the script was looking for an empty form and trying to shove an empty reference into a already defined value. Its confused. I know I was. :tongue: After reading how the function FindRandomReferenceOfTypeFromRef works on the CK wiki, I put this together. It is heavily commented and hopefully understood. I do not know if it works. May be worth a try, at any rate. ;some event/function start OldBaseObject = Target.GetBaseObject() While !Stop If !CurrentTarget ;is not a valid value ;attempt to give CurrentTarget a valid value ;this may only run once per hosting record at script start CurrentTarget = Game.FindRandomReferenceOfTypeFromRef(OldBaseObject, CenterMarker, 51200) ;returns as an object reference automatically Else ;is a valid value ;compare to desired value If !(CurrentTarget.GetBaseObject() == OldBaseObject) ;does not match desired value ;get new value CurrentTarget = Game.FindRandomReferenceOfTypeFromRef(OldBaseObject, CenterMarker, 51200) ;returns as an object reference automatically Else ;it does match so this is what we want to work with StoredTarget = CurrentTarget Stop = true ;stop this loop EndIf EndIf If !CurrentTarget ;is not a valid value ;we looped but found no valid value -- get out of this thing Stop = True ;stop this loop EndIf EndWhile ;do whatever work with the desired value of StoredTarget ;some event/function end ObjectReference Property Target Auto {desired target reference} ObjectReference Property CenterMarker Auto {search center reference point} Form OldBaseObject ;form variable for base form of Target ObjectReference CurrentTarget ;object reference variable for current random reference of Target base form ObjectReference StoredTarget ;object reference variable used when current random reference base matches the desired Target base form I tried to err on the side of caution so there maybe more here than is necessary. Link to comment Share on other sites More sharing options...
Deleted4782829User Posted April 28, 2014 Author Share Posted April 28, 2014 i didn't explain myself properly, here's the whole function: Function ChangeBanners() BannerCount = 9 ;there are 9 banners in the cell that has to be replaced Stop = False ;finds the current banner in the cell OldBannerRef = Game.FindClosestReferenceOfAnyTypeInListFromRef(BannerList, CustomMarker_BannerColorPicker, 51200) as ObjectReference ;get the base form of that banner OldBanner = OldBannerRef.GetBaseObject() as Form ;get the type in int OldBannerType = OldBanner.GetType() as Int ;get the banner form at this location in this list (selectbanner is defined in another part of this script) NewBanner = BannerList.GetAt(SelectBanner) ;start loop of finding banners, placing them and of deleting old onces. While (BannerCount != 0) && !Stop BannerCount -= 1 ;makes sure that the target is none, so the script doesn't jump over the selecting of new banner part Target = None ;loop to find a new banner, "!(Target.GetBaseObject() == OldBanner)" doesn't seem to work, i have tried multiple ways of coding this part While !Stop && !(Target.GetBaseObject() == OldBanner) ;find a banner of type, max distance of 51200 from a marker i have in the cell Target = Game.FindRandomReferenceOfTypeFromRef(OldBanner, CustomMarker_BannerColorPicker, 51200) as ObjectReference ;if by any means the script can't find anything it needs to stop if !Target Stop = True endif EndWhile ;gets the position and angle of the oldbanner float floatX = Target.GetPositionX() float floatY = Target.GetPositionY() float floatZ = Target.GetPositionZ() float floatAngleX = Target.GetAngleX() float floatAngleY = Target.GetAngleY() float floatAngleZ = Target.GetAngleZ() ;places a new banner on the oldbanner ObjectReference BannerRef = Target.PlaceAtMe(NewBanner).SetPosition(floatX, floatY, floatZ) BannerRef.SetAngle(floatAngleX, floatAngleY, floatAngleZ) ;disables and deletes the oldbanner Target.DisableNoWait() Target.Delete() EndWhile ;this should now happen 9 times on all 9 banners in the cell EndFunction ;---------------------------------------------------------- ; Banners ;---------------------------------------------------------- Bool Stop int SelectBanner int BannerCount int OldBannerType Form NewBanner Form OldBanner FormList Property BannerList Auto ObjectReference Property Target Auto ObjectReference Property OldBannerRef Auto ObjectReference Property CustomMarker_BannerColorPicker AutoThe idea is that; there are banners i want to change in a cell, i want to change between a list of banners, i got the list part working. the part i don't have working is the part i mentioned in the OP,how it is suppose to work is that, the script looks for the current banner in the cell and marks that form of banner.then the script tries to get the banner in the cell as an objectreference, the problem is that the "!(Target.GetBaseObject() == OldBanner)" part doesn't work, it doesn't exclude banners that aren't of the new banner form, it is only suppose to pick oldbanners and not the new one it just replaced. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 28, 2014 Share Posted April 28, 2014 Have you tried adding any debug.trace statements to see what is being returned by what and being compared by what? Perhaps by doing that you can see what is going on and have a better idea on how to tweak the script. Link to comment Share on other sites More sharing options...
Deleted4782829User Posted April 29, 2014 Author Share Posted April 29, 2014 i have, it finds the type, but it doesn't care which form the object is, i can't get it to differentiate between a newbanner and an oldbanner. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 29, 2014 Share Posted April 29, 2014 Maybe you need to rethink the process? Looks like you have 9 known references that you want to change at user discretion. The user selects a design/color and all 9 change to that. Why not pre-place each design/color and link them to their own enable parent xmarker? Enable/Disable each marker as needed. I suppose that might get too crowded should you have quite a few designs... Any possibility of doing it that is more fixed and less random? Perhaps additional FormLists or maybe Arrays with while loops to cycle through the entries? Link to comment Share on other sites More sharing options...
Deleted4782829User Posted April 29, 2014 Author Share Posted April 29, 2014 i have thought of that, but that would be an absolute last resort, there are over 36 different banners, placing them at each different location, would result in 324banners in total, which is unpractical. Link to comment Share on other sites More sharing options...
Recommended Posts