[Papyrus]Calling custom functions on placed items.

Post » Tue Jun 19, 2012 11:21 pm

Hey, I ran into another problem while trying to create a useable chessboard.

The following script fails to compile with the error: "Initialize is not a function or does not exist"
Spoiler

Function Initialize(Int pColNum)    Cells = new ObjectReference[8]    ColNum = pColNum    Int Counter = 0    While (Counter < 8)	    If((pColNum % 2) == 0)		    If((Counter %2) == 0)			    Cells[Counter] = Self.PlaceAtMe(CTG_ChessBoardBlackCell)			    Cells[Counter].MoveTo(Self,0,Counter * 50,10)			    Cells[Counter].Initialize(False)		    Else			    Cells[Counter] = Self.PlaceAtMe(CTG_ChessBoardWhiteCell)			    Cells[Counter].MoveTo(Self,0,Counter * 50,10)			    Cells[Counter].Initialize(True)		    EndIf	    Else		    If((Counter %2) == 0)			    Cells[Counter] = Self.PlaceAtMe(CTG_ChessBoardWhiteCell)			    Cells[Counter].MoveTo(Self,0,Counter * 50,10)			    Cells[Counter].Initialize(True)		    Else			    Cells[Counter] = Self.PlaceAtMe(CTG_ChessBoardBlackCell)			    Cells[Counter].MoveTo(Self,0,Counter * 50,10)			    Cells[Counter].Initialize(False)		    EndIf	    EndIf    EndWhileEndFunction

The following script, attached to both "CTG_ChessBoardBlackCell" and "CTG_ChessBoardWhiteCell", defines the function "Initialize".

Spoiler

Scriptname CTG_ChessBoardCellScript extends ObjectReference  Int FigureBool WhiteFunction Initialize(Bool pWhite)    White = pWhite    Figure = 0EndFunctionBool Function IsWhite()    Return WhiteEndFunctionFunction SetFigure(Int pFigure)    Figure = pFigureEndFunctionInt Function GetFigure()    Return FigureEndFunction

Any Idea why this is not working?
User avatar
Kelly Osbourne Kelly
 
Posts: 3426
Joined: Sun Nov 05, 2006 6:56 pm

Post » Wed Jun 20, 2012 1:25 am

Try this:

(Cells[Counter] as CTG_ChessBoardCellScript).Initialize(False)
User avatar
Justin Bywater
 
Posts: 3264
Joined: Tue Sep 11, 2007 10:44 pm

Post » Wed Jun 20, 2012 11:54 am

Lol of course. Thank you very much. I tried every other cast that seemed logical but this one.
User avatar
Roberto Gaeta
 
Posts: 3451
Joined: Tue Nov 06, 2007 2:23 am

Post » Wed Jun 20, 2012 6:33 am

Yeah, always cast as the script that contains your functions...be sure to check that the result isn't a "none" before calling your functions of course.
User avatar
James Shaw
 
Posts: 3399
Joined: Sun Jul 08, 2007 11:23 pm

Post » Wed Jun 20, 2012 3:39 am

Yeah of course. So this way I am able to create a two dimensional array now I just need to figure out how to turn that in an actual useful object to create a checkers minigame.

Maybe making the Board Object an actual table and make the cells invisible should be my first step.
User avatar
Dan Scott
 
Posts: 3373
Joined: Sun Nov 11, 2007 3:45 am

Post » Wed Jun 20, 2012 1:59 am

I made a linked lists implementation quite a while ago (See the helpful link in my siggie) for 2-dimensional array simulation.
User avatar
Chad Holloway
 
Posts: 3388
Joined: Wed Nov 21, 2007 5:21 am


Return to V - Skyrim