How to use interfaces?

Just starting out? Need help? Post your questions and find answers here.
Mijikai
Posts: 12
Joined: Sun Sep 17, 2017 9:59 am

How to use interfaces?

Post by Mijikai »

I need some oop for a game so i naturally tried to use interfaces for objects just like in PB.
Seems like its not possible... how would i solve this problem?

Btw. labes in the datasection did not work, thats why i moved the vtable into a struct.

What i tried:

Code: Select all

EnableExplicit

Structure DUMMY
  *vt
  value.i
EndStructure

Structure VTABLE
  *proc[16]
EndStructure

Structure GAME
  dummy.DUMMY
  vtable.VTABLE
EndStructure

Interface I_DUMMY
  Hello.i()
EndInterface

Global game.GAME

Procedure.i Hello(*dummy.DUMMY)
  MessageRequester("Test",*dummy\value)
  ProcedureReturn 456
EndProcedure

Procedure.i Init()
  Protected *test.I_DUMMY
  
  game\vtable\proc[0] = @Hello()
  
  game\dummy\vt = @game\vtable
  game\dummy\value = 123
  
  Debug *test\Hello()
EndProcedure


Init()
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: How to use interfaces?

Post by Peter »

I do not work with interfaces. Therefore I cannot help you here. But...
Mijikai wrote: Sat Feb 25, 2023 10:25 amBtw. labes in the datasection did not work
sure? The example found in the documentation works for me. Can you post some code where it doesn't work?
Mijikai
Posts: 12
Joined: Sun Sep 17, 2017 9:59 am

Re: How to use interfaces?

Post by Mijikai »

I mainly use PB so i guess its just different.

Datasection example:

Code: Select all

Debug ?label;<- does not exist

DataSection
  label:
EndDataSection
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: How to use interfaces?

Post by Peter »

If you create a datasection (example taken from the document):

Code: Select all

DataSection
  NumericalData:    
  Data.l 100, 200, -250, -452, 145
  StringData:
  Data.s "Hello", "This", "is ", "What ?"
EndDataSection
then SpiderBasic makes a JavaScript array out of it:

Code: Select all

var sb_data = [100, 200, -250, -452, 145, "Hello", "This", "is ", "What ?"];
and create variables from the labels which contain the positions of the elements:

Code: Select all

l_numericaldata = 0;
l_stringdata = 5;
An internal variable called sb_datapointer contains the current position of the element and this is incremented by one with each Read.

If you want to get the "address" of a label, you need some inline JavaScript:

Code: Select all

Define NumericalDataLabel
Define StringDataLabel

! v_numericaldatalabel = l_numericaldata; // corresponds to ?NumericalData
! v_stringdatalabel = l_stringdata; // corresponds to ?StringData

Debug NumericalDataLabel
Debug StringDataLabel
Maybe this explanation helps a little bit in dealing with datasections in SB.
Mijikai
Posts: 12
Joined: Sun Sep 17, 2017 9:59 am

Re: How to use interfaces?

Post by Mijikai »

Thanks for the reply.
Post Reply