Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Need help with convert Blitz3D code to thinBasic

  1. #1

    Need help with convert Blitz3D code to thinBasic

    Hello everbody!

    I'm novice in programming. A couple of months ago I started learning Blitz3D, but soon realized that he uses the old DirectX 7. And recently I found in the Internet a great BASIC compiler - thinBasic. It's realy powerful and useful basic. I have some questions about programming in thinBasic.

    This is my Simple code in Blitz3D:

    Type Monstr
    Field number
    End Type

    For i=0 to 10
    enemy.Monstr = New Monstr
    enemy\number = i
    Next

    ; This three rows is interesting me. I need to convert this rows into thinBasic code.
    For enemy.Monstr = Each Monstr ; whether in the thinbasic this comand (like EACH)?
    enemy\number = enemy\number +1
    Next

    End

    P.S. Sorry my BAD English!

    Thanks in advance!

  2. #2

    Re: Need help with convert Blitz3D code to thinBasic

    Hi,

    welcome to the forum. FOR EACH is not supported to my knowledge. You have to use a linked list and then read through it with the regular looping commands.

    Cheers
    Michael

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Need help with convert Blitz3D code to thinBasic

    Hi Bagamut and welcome to thinBasic.

    Few clarification about thinBasic
    thinBasic is not a compiler but an interpreter, it means it does not produce any machine code but just read your source code and interpret it on the fly.
    thinBasic is not an object oriented language so whenever there is some code using objects we need to convert it into something different, usually types and functions.

    EACH is a construct of OOP. In thinBasic we still do not have it so you need to use standard loops.

    Your code can be something like:
    [code=thinbasic]
    '---Define your new type
    Type Monstr
    Number AS LONG
    '... other type elements (properties in OOP)
    End Type

    '---Define monsters
    dim Enemy(10) as Monster

    '---Fill in some data
    For i=1 to 10
    enemy(i).Number = i
    Next[/code]

    But depending on the situation you can allocate monster elements dynamically.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4

    Re: Need help with convert Blitz3D code to thinBasic

    Quote Originally Posted by Michael Hartlef
    Hi,

    welcome to the forum. FOR EACH is not supported to my knowledge. You have to use a linked list and then read through it with the regular looping commands.

    Cheers
    Michael
    Could you write an example plz!

  5. #5

    Re: Need help with convert Blitz3D code to thinBasic

    there is a detailed example about using linked list in the thinbasic examples:
    C:\thinBasic\SampleScripts\LL\Test_LL.tbasic
    and about the linked list concept:
    http://en.wikipedia.org/wiki/Linked_list

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Need help with convert Blitz3D code to thinBasic

    I do not think loops involving EACH keyword has to be handled using lists.
    Classical FOR/NEXT looping through elements is a structure (whatever complex it can be) is enough.
    The point is to understand the complete structure of enemy and/or monster, what is the first and what is the second and how they are organized.
    Than use FOR/NEXT at whatever needed level of the structure to loop each of the elements of an array.

    If dynamic creation of UDT is needed so there is no knowlegde at programming time of how many elements will be allocated, than there will be many different techniques that can be used to store data and loop on them.

    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7

    Re: Need help with convert Blitz3D code to thinBasic

    Quote Originally Posted by Bagamut
    Quote Originally Posted by Michael Hartlef
    Hi,

    welcome to the forum. FOR EACH is not supported to my knowledge. You have to use a linked list and then read through it with the regular looping commands.

    Cheers
    Michael
    Could you write an example plz!
    Hi,

    I will try to provide you with something hopefully tonight when I am back from work and the kid is in bed. I think about a more dynamic approach with memory allocation. That should be better than a linked list.

    Btw. what is your native language? I have no problems understanding of what you write.

    Cheers
    Michael

  8. #8

    Re: Need help with convert Blitz3D code to thinBasic

    Quote Originally Posted by Michael Hartlef
    Hi,

    I will try to provide you with something hopefully tonight when I am back from work and the kid is in bed. I think about a more dynamic approach with memory allocation. That should be better than a linked list.
    Thanks in advance! Does the thinBasic support dynamic arrays of UDTs?

    Quote Originally Posted by Michael Hartlef
    Btw. what is your native language? I have no problems understanding of what you write.

    Cheers
    Michael
    Russian is my native language.

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Need help with convert Blitz3D code to thinBasic

    Quote Originally Posted by Bagamut
    Does the thinBasic support dynamic arrays of UDTs?
    Dynamic arrays of UDT yes. Arrays of UDT are just standard arrays.


    Dynamic arrays inside UDT no but it is something I will work for future versions because I would definitely like to have it.
    A possible work around ven on this necessity is possible using dynamic strings inside an UDT and over-impose logical array structures to that strings. You need latest beta version 1.8.1

    An example:
    [code=thinbasic]
    #MINVERSION 1.8.1

    '---Define an UDT having a dynamic string inside
    Type tMyUDT
    MyLong As Long
    MyArrayOnStringBuff As String
    Whatever As Ext
    End Type

    '---Some variables
    Dim nItems As Long
    Dim MyUDT As tMyUDT

    '---How many items you want in your logical array
    nItems = 10

    '---Dimension your string for exactly the size of the needed data mult number of items
    MyUDT.MyArrayOnStringBuff = Repeat$(SizeOf(Long) * nItems, $NUL)

    '---Define a logical array that over-impose at the same memory location of
    '---dynamic string inside your UDT
    Dim MyArrayOfLongs(nItems) As Long At StrPtr(MyUDT.MyArrayOnStringBuff)

    '---Fill your logical array. In reality you are filling dynamic memory inside UDT
    MyArrayOfLongs(1) = 1,2,3,4,5,6,7,8,9,10

    '---output data
    MsgBox 0, "OK, data is:" & $CRLF & _
    Join$(MyArrayOfLongs, $CRLF)

    '---Now add few more items
    Dim lMoreItems As Long = 5
    nItems = nItems + lMoreItems

    '---Increase size of the dynamic string with more space for new items
    '[!] Note the += assignment used to increment current buffer
    MyUDT.MyArrayOnStringBuff += Repeat$(SizeOf(Long) * lMoreItems, $NUL)
    '---Redim your logical array
    ReDim MyArrayOfLongs(nItems) As Long At StrPtr(MyUDT.MyArrayOnStringBuff)

    '---Fill new items
    MyArrayOfLongs(11) = 11,12,13,14,15,16

    '---output data
    MsgBox 0, "Data after inserting new ietms:" & $CRLF & _
    Join$(MyArrayOfLongs, $CRLF)

    [/code]
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  10. #10
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Need help with convert Blitz3D code to thinBasic

    I think it is possible to create dynamic arrays of UDT, just like with any other data type:
    [code=thinbasic]
    Uses "Console"

    Type tPoint
    x As Single
    y As Single
    End Type

    ' -- Create original array
    Dim Points(2) As tPoint

    Points(1).x = 1
    Points(1).y = 2

    Points(2).x = 3
    Points(2).y = 4

    ' ### PRINT IT OUT ###
    Points_ToConsole(points)

    ' -- Change size, but preserve elements content
    ReDim Preserve Points(3)

    Points(3).x = 5
    Points(3).y = 6

    ' ### PRINT IT OUT ###
    Points_ToConsole(points)


    ' -- Change size, but erase the contents
    ReDim Points(4)

    ' ### PRINT IT OUT ###
    Points_ToConsole(points)

    WaitKey

    Sub Points_ToConsole( points() As tPoint)

    Local i As Long
    Local numPoints As Long = UBound(points)

    PrintL "Total items: "+Format$(numPoints)
    For i = 1 To numPoints
    PrintL "item #"+Format$(i), points(i).x, points(i).y
    Next
    PrintL

    End Sub
    [/code]


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Page 1 of 2 12 LastLast

Similar Threads

  1. Blitz3D (B3D) to M15
    By Michael Hartlef in forum M15 file format
    Replies: 6
    Last Post: 31-07-2008, 21:21

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •