Jump to content

Purebasic Import - 1st try


smateja
 Share

Recommended Posts

But I still wouldn't use it for something like LeadWerks. Some of the way PureBasic handles things is a real pain.

LOL :P you say that because you don't want to be the teacher that writes purebasic tutorials ;)

 

I did not use purebasic enought to fully understand if it's a pain or not. Sure the language is a little basic (i like pleonasms :blink:) but if you know only this one and like it, maybe why not.

 

The biggest disavantage is that you'll get less help from the purebasic community than from the c++ community if you were a beginner. So for beginners who can't find solutions by themselves, C++ is much much much better, i agree.

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

okay -

 

i found my problem why i don´t see water etc. - i thx wchriss for his working example.

 

My Fault was - that i do this code:

 

 

framework = LECreateFramework()

 

If framework >0

 

Lua = LEGetLuaState()

LELua_pushobject(Lua, framework );

LELua_setglobal(Lua, "framework ");

LELua_pop(Lua, 1);

 

 

if i renamed framework to fw - all works fine - water - sky etc. - sorry for this and thx.

Link to comment
Share on other sites

if i renamed framework to fw - all works fine - water - sky etc. - sorry for this and thx.

you can call your variable framework

 

only here LELua_setglobal(Lua, "fw");

 

"fw" is not a variable, it's leadwerks engine internally predefined name used to link the engine framework to your external variable. So this "fw" within quotes cannot be changed, it must match the name defined in the engine.

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

you can call your variable framework

 

only here LELua_setglobal(Lua, "fw");

 

"fw" is not a variable, it's leadwerks engine internally predefined name used to link the engine framework to your external variable. So this "fw" within quotes cannot be changed, it must match the name defined in the engine.

 

Thx for explaining me. I now renamed it to framework and all works fine.

But now i got another Problem - if i include i the headgen with xinclude i mmust correct to set the leadwerks.pb variables global - otherwise it crashes. Mybay you can correct this in new headgen version. try use enableexplecit command in PB.

 

 

2nd: i got a litte problem 2 handle vec3 results.

My code:

 


 While (LEKeyHit(#KEY_ESCAPE)=0) And (LEAppTerminate()=0)


  ;-Mouse Look

         mouse_x.f=Curve(LEMouseX()-LEGraphicsWidth()/2,mouse_x.f,6.0)
         mouse_y.f=Curve(LEMouseY()-LEGraphicsHeight()/2,mouse_y.f,6.0)

        LEMoveMouse(LEGraphicsWidth()/2,LEGraphicsHeight()/2)
        camrotation=LEEntityRotation(camera,Vec3(VResult, mouse_y.f, mouse_x.f, 0))
        camrotationx.f=camrotationx.f-mouse_x/10
        camrotationy.f=camrotationy.f+mouse_y/10
        LERotateEntity(camera,Vec3(VResult, camrotationy.f, camrotationx.f, 0))


;-Player movement        
      move=LEKeyDown(#KEY_W)-LEKeyDown(#KEY_S)
      strafe=LEKeyDown(#KEY_D)-LEKeyDown(#KEY_A)

 ;-Set cntroller Input     
      LEUpdateController(player,Vec3(VResult, camrotationy.f, camrotationx.f, 0),move,strafe,jumo,0.5);

 ;- PosCam 
      playerpos=LEEntityPosition(player,Vec3(VResult))
[b]      ; *y.playerpos=*y.playerpos+1.75
     ; LEPositionEntity(camery,playerpos)[/b]

 

when i un-rem the bolden codelines (the last 2 lines) i get enginecrashes - don´t know @ this time how to handle correct 2 use the playercontroller und position wit Vec3.

Maybe someone can help me out.

 

Thx a lot

 

PS: i added as attachment the updated leadwerks-include with global variables if someone would like to xinclude in projects (And as backup for myself ;) - i like backups in the cloud G*).

leadwerks_pb_include.txt

Link to comment
Share on other sites

[b]      ; *y.playerpos=*y.playerpos+1.75
     ; LEPositionEntity(camery,playerpos)[/b]

 

ok, i'll update the generator to add global before the wrappers

 

what is *y .playerpos ? why not playerpos\Y ?

and what is camery ? :P this is what happens with languages that are not strict on variable declarations :lol:

 

There is an option in purebasic to force variable declarations, maybe you should activate it.

 

and this is wrong : playerpos=LEEntityPosition(player,Vec3(VResult))

because the C++ header transforms the engine .dll procedure into a function and the purebasic header currently doesn't

 

it is declared like this : Prototype LEEntityPosition ( entity.i, *position.TVec3, Globaly.i=0 )

 

so i don't understand why purebasic accepts your syntax and does not complain he has nothing to assign to playerpos because the prototype is not a function ?????

 

the current syntax in purebasic is : LEEntityPosition(player, playerpos, 0)

 

if we find a way to transform procedures that return 1 value into functions, why not. i did it in the pascal header, but i currently don't know how to do it in purebasic. Without this, you'll have to be careful and look at the prototypes when traducing c++ tutorials because syntax may differ (but not allways, because sometimes engine.dll exports functions, there is no rule).

 

Daamn ! i'm teaching purebasic with a trial version after reading a pdf documentation 10 minutes ;) crazy me !

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

Daamn ! i'm teaching purebasic with a trial version after reading a pdf documentation 10 minutes ;) crazy me !

 

Yes Man - your good in :lol: - sorry but i am not a programmer - i am a network technican and a little bit hobby programming learner.

 

what is *y .playerpos ? why not playerpos\Y ?

 

i tried playerpos\Y - but it want work - i defined

 

Structure playerpos

X.f

Y.f

Z.f

EndStructure

 

but it also don´t work.

 

 

mmhm - think i am a little lost - because i don´t understand how to get 3 variables into one -> playerpos=LEEntityPosition(player,Vec3(VResult)) and then use them with LEPositionEntity(camera,playerpos,0)

 

This want work:

 

playerpos=LEEntityPosition(player,Vec3(VResult))

playerpos\y=playerpos\y+1.75

LEPositionEntity(camera,playerpos,0)

 

 

 

my actual complete code - looks like:

 


EnableExplicit

XIncludeFile ("hw_engine.pbi")


;XIncludeFile ("hw_controlcam.pbi")
;XIncludeFile ("hw_screenrequester.pbi")


Define VResult.TVec3   ;if an expression requires more than one vec3 then define VResult2.TVec3, VResult3TVec3, etc ... for each vec3
Define sx.i
Define sy.i
Define framework.i
Define Lua.i
Define Camera.i
Define scene.i
Define player.i
Define font.i

Define move.f
Define strafe.f
Define jump.f

Define camrotation
Define camrotation_x.f
Define camrotation_y.f

Define mouse_x.f
Define mouse_y.f

Define playerpos

LERegisterAbstractPath(GetCurrentDirectory())
LESetAppTitle("Hiveworx Framework")

sx = 1024
sy = 768



If LEGraphics(sx,sy)>0
  framework = LECreateFramework()

  If framework>0    

     Lua = LEGetLuaState()
     LELua_pushobject(Lua, framework);
     LELua_setglobal(Lua, "fw");
     LELua_pop(Lua, 1);

     Camera = LEGetLayerCamera(LEGetFrameworkLayer(0))
     LEPositionEntity(camera, Vec3(VResult,0, 350,0))


     scene = LELoadScene("abstract::test001.sbx")
     LEEntityType(scene,2,1)

     player = LECreateController(1.8,0.4,0.5,45,0)
     LEEntityType(player,1)

     LESetStats(2)

     font=LELoadFont("abstract::Arial12Shadow")
     LESetFont(font)

     move.f=0.0
     strafe.f=0.0
     jump.f=0.0


     LEMoveMouse(LEGraphicsWidth()/2,LEGraphicsHeight()/2)

     LEHideMouse()

    XIncludeFile ("hw_grafikoptionen.pbi")

    While (LEKeyHit(#KEY_ESCAPE)=0) And (LEAppTerminate()=0)


  ;-Mouse Look

         mouse_x.f=Curve(LEMouseX()-LEGraphicsWidth()/2,mouse_x.f,6.0)
         mouse_y.f=Curve(LEMouseY()-LEGraphicsHeight()/2,mouse_y.f,6.0)

        LEMoveMouse(LEGraphicsWidth()/2,LEGraphicsHeight()/2)
        camrotation=LEEntityRotation(camera,Vec3(VResult, mouse_y.f, mouse_x.f, 0))
        camrotation_x.f=camrotation_x.f-mouse_x/10
        camrotation_y.f=camrotation_y.f+mouse_y/10
        LERotateEntity(camera,Vec3(VResult, camrotation_y.f, camrotation_x.f, 0))


;-Player movement        
      move=LEKeyDown(#KEY_W)-LEKeyDown(#KEY_S)
      strafe=LEKeyDown(#KEY_D)-LEKeyDown(#KEY_A)

 ;-Set controller Input     
      LEUpdateController(player,Vec3(VResult, camrotation_y.f, camrotation_x.f, 0),move,strafe,jump,0.5);

      ;- Position Camera

      playerpos=LEEntityPosition(player,Vec3(VResult))
      ;playerpos\y=playerpos\y+1.75
      LEPositionEntity(camera,playerpos,0)

       LEUpdateFramework() ;Update timing And world
        LERenderFramework() ;Render



        LESetBlend(1)

        LEDrawText("CamPosX: ",800,20)
        LEDrawText("CamPosY: ",800,40)
        LEDrawText("CamPosZ: ",800,60)

        LESetBlend(0)

        LEFlip(0) ;Send to screen




     Wend      

   Else
     LEAppLog("ERROR: Failed to create Framework")
  EndIf

  LEFreeFramework(framework)
Else
  LEAppLog("ERROR: Failed to create or set graphics mode")
EndIf


LEEndRender()
CloseLibrary(#Engine_Library)

 

 

i commented out playerpos\y=playerpos\y+1.75 because don´t know how to define the structure.

Line LEPositionEntity(camera,playerpos,0) causes crashing the engine.

 

grettings

Link to comment
Share on other sites

 

Line LEPositionEntity(camera,playerpos,0) causes crashing the engine.

 

maybe because playerpos is wrong

 

do LEEntityPosition(player, playerpos, 0) instead of playerpos=LEEntityPosition(player,Vec3(VResult)) and see if it's better

 

i'll look at your code this weekend, thanks for posting, it's much easyer when code is supplyed

 

EDIT :

mmhm - think i am a little lost - because i don´t understand how to get 3 variables into one -> playerpos=LEEntityPosition(player,Vec3(VResult)) and then use them with LEPositionEntity(camera,playerpos,0)

 

With Purebasic you must learn everything you can about :

- pointers,

- procedures and "by reference parameters" and 'By Value" parameters.

- the difference between a procedure with procedurereturn and without procedurereturn

- how can a procedure return data without procedurereturn

- understand the difference between :

Prototype.i LESomethingh1 ( )

Prototype LESomethingh2 ( aaaaa.i )

Prototype LESomethingh3 ( *aaaaa.BYTE)

 

 

Purebasic is not easy at all, it makes heavy usage of pointers and has no abstraction layer to simplify your programming task.

So if you don't understand those concepts, you're just playing loto throwing commands hopiing it'll work, and you'll get Access violations every 5 minutes.

 

vec3 is a procedure with procedurereturn (wich equals a functiion in other languages) so you can say variable = function to get the value from procedurereturn. The Vresult is a dummy variable to store the result of the structure sent back by procedurereturn, this is needed because purebasic has problems with structures and procedurereturn. Vresult is a dummy variable only used in expressions where you want to use the function immediately and not need to keep the result after.

Is you have a specific variable to store the result and want to keet the value you can use it instead of vresult. like this LEPositionEntity(camera, Vec3(playerpos, playerpos\x, playerpos\y+10.75, playerpos\z),0)

but you can also write

playerpos\y=playerpos\y+10.75

LEPositionEntity(camera, playerpos,0)

in both case you MUST declare Define playerpos.Tvec3

because LEPositionEntity second parameter is a POINTER and a pointer can point to anything without type checking. This means it won't complain, but if the type provided is not the one expected it will symply CRASH.

 

here's your fixed code Camerasample.zip

 

Sorry, but learning you how to program in purebasic and how to use pointers is far out of scope of this forum. it's not an easy task, and pointers is a difficult concept to understand, nearly impossible in 5 lines of text in a forum.

Pointers is the main reason of ACCESS VIOLATIONS and this is why modern languages like java totally got rid of pointers. Even Microsoft engineers made plenty of AV (blue screens) with pointers in windows 95, they did not get better at programming with vista or seven, they simply use now modern object languages that do not require pointers.

So purebasic is a language that requires pointers and very good programming skills (not really what's expected from a basic) and you'll keep comming back here every 3 lines of codes you write with and AV that stops you if you don't masterize pointers.

 

PS: updated the header generator

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...