Jump to content

Question about script files and function access


Kasrith
 Share

Recommended Posts

I have been creating a simple HUD for player stats display and weapon stats display. This is just playing around learning the systems involved, not for any specific gameplay model.

 

I would like to consolidate all the HUD code into a single script instead of having some code in Player.lua, some code in weapon.lua, etc, and then just call a repaint or update function from the requisite player or weapon script.

 

How would one go about doing this?

 

Does 'importing' or 'requiring' a script duplicate that entire script inside the importing script or just allow access to its functions and variables?

Link to comment
Share on other sites

if you want permanent update/drawing do a DrawText() in the UpdateWorld() function

 

I prefer getter/setter functions for private vars like GetHealthpoints()

 

or if you will do more stuff related to an update (just do something when HP or AMMO has changed) you can also use the observer to hold your code clean

 

or put everything for HUD stuff in a pivot. there are many solutions.

It doesn´t work... why? mhmmm It works... why?

Link to comment
Share on other sites

if you want permanent update/drawing do a DrawText() in the UpdateWorld() function

 

What do you mean buy this? DrawText() should be in PostRender() otherwise it won't be seen.

 

I agree with putting everything HUD related in it's own pivot OR put it ALL in the player script. Since the player script already has access to the weapon prefab entity, which means it can access the weapon script, it can access all the data it needs to do the HUD. Putting it in it's own entity, pivot for example, means you have to think more about exposing the required data to it. That script could have parameters to the player entity and weapon entity to get it's info though and be pretty much the same.

 

Does 'importing' or 'requiring' a script duplicate that entire script inside the importing script or just allow access to its functions and variables?

 

Generally this just defines the functions (I say generally because they can also create global variables). If you define the functions multiple times it's not a big deal since the functions are all the same def anyway.

Link to comment
Share on other sites

I meant use the function Script:UpdateWorld() from an xxx.lua class to write text by getting the main context from the app.lua

 

like

 

App.context:DrawText(test,x,y)

+ do some setblendmode stuff before and after

 

 

should work i guess?

 

I prefer DDD so I would seperate so much as possible and so less then needed that the code is logical correct with the real world.

 

vars from classes also should always be private. to get write/read access use getters/setters

 

a weapon cant draw anything in reallife so you need a hud class also. the hud class onnly can draw. so the hud class have to ask weapon class how much ammo is available to draw it on the screen.

It doesn´t work... why? mhmmm It works... why?

Link to comment
Share on other sites

DrawText() will only be seen on screen if done from the PostRender() function.

 

Lua doesn't have any idea of private. You can still make getters/setters of course but the language itself won't force any rules of private.

 

Games aren't real-life :). You are correct that you could do exactly what you are saying and be more real-life like, but there are a million ways to skin a cat in the video game world you know :)

Link to comment
Share on other sites

DrawText() will only be seen on screen if done from the PostRender() function.

 

ah ok so nvm biggrin.png and just put code in PostRender() not UpdateWorld()

 

Games aren't real-life smile.png. You are correct that you could do exactly what you are saying and be more real-life like, but there are a million ways to skin a cat in the video game world you know smile.png

 

sure but when the games become bigger its hard to hold the overview of the code. its just my opinion. there are million ways to do the same wink.png

It doesn´t work... why? mhmmm It works... why?

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...