Jump to content

Recommended Posts

Posted

hey everyone just after a little help with this code...

 

Book[] Property MyBooks Auto
Function AddBooks()
Actor aPlayer = Game.GetPlayer()
int i = MyBooks.Length
while (i > 0)
i -= 1
aPlayer.AddItem(MyBooks, 1)
endWhile
EndFunction
;----------------------------------------- ON OPTION SELECT ---------------------------------------------------------
Event OnOptionSelect(int option)
elseif (option == OIDBooks)
AddBooks = !AddBooks
SetToggleOptionValue(option, AddBooks)
AddBooks()
-----------------------------------------------------------------------------------------------------------------------------------
so this works perfectly for adding the books ive created to a players inventory though a toggle in my MCM menu.. but.. i want to be able to remove them too through the same toggle.. the code to remove the items is this:
Function AddBooks()
Actor aPlayer = Game.GetPlayer()
int i = MyBooks.Length
while (i > 0)
i -= 1
aPlayer.RemoveItem(MyBooks, 1)
endWhile
EndFunction
-------------------------------------------------------
which also works perfectly.. the problem is with my somewhat limited experience i cant intergrate them.. its either one or the other.. papyrus will only allow one instance of AddBooks() and ive tried adding Else, If.. you know to try seperating them but im really struggling..
any help would be greatly appreciated
Posted

Call two separate functions. One to add the books and one to remove the books. You'll have to change up your OnOptionSelect and associated menu functions to use a bool variable to toggle.

 

Something like:

 

  Reveal hidden contents

 

Posted
What an amazing reply.. o did Initially try a remove function but didn't know about the bool variable so maybe that's why it wasn't working.. also as for doing the work after your absolutely right I just didn't know how to implement it.. I really appreciate the time you've taken to reply!
Posted

You can also use a single function and check for the AddBooks variable.

Function AddBooks()
    Actor aPlayer = Game.GetPlayer()
    int i = MyBooks.Length    
    while (i > 0)
        i -= 1
           if Addbooks
              aPlayer.AddItem(MyBooks[i], 1)
           else
              aPlayer.RemoveItem(MyBooks[i], 1)
    endWhile
EndFunction

What if the player removed one or more of the books meanwhile?

Posted

the functions are working perfectly now.... what im trying to do now is to display a different message when the toggle is activated in MCM like so

 

Event OnOptionSelect(int option)
If (option == OIDBooks)
BooksAdded = !BooksAdded
Debug.MessageBox("Books added to inventory")
if BooksAdded == True
Debug.MessageBox("Books removed from inventory")
SetToggleOptionValue(option, BooksAdded)
endif
but its displaying both messages one after eachother on a single toggle
Posted
Event OnOptionSelect(int option)


If (option == OIDBooks)

BooksAdded = !BooksAdded

SetToggleOptionValue(option, BooksAdded)

if BooksAdded == True

Debug.MessageBox("Books added to inventory")

if BooksAdded == false

Debug.MessageBox("Books removed from inventory")


endif


that doesnt work either

Posted

Calling the functions from OnOptionSelect like this works perfectly:

 

Event OnOptionSelect(int option)

If (option == OIDBooks)

BooksAdded = !BooksAdded

SetToggleOptionValue(option, BooksAdded)

If BooksAdded == True

AddBooks()

Else

RemoveBooks()

EndIf

Endevent

 

But doing it like this is causing issues..

 

Event OnOptionSelect(int option)

If (option == OIDBooks)

BooksAdded = !BooksAdded

SetToggleOptionValue(option, BooksAdded)

EndIf

EndEvent

 

Event OnConfigClose()

RegisterForSingleUpdate(0.1)

EndEvent

 

Event OnUpdate()

If BooksAdded == True

AddBooks()

Else

RemoveBooks()

EndIf

EndEvent

 

Calling the function from OnUpdate makes the menu add the books again automatically everytime the menu is closed

  • Recently Browsing   0 members

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