Author Topic: Using units  (Read 3142 times)

0 Members and 1 Guest are viewing this topic.

Offline Finchie

  • Major(1)
  • Posts: 1
Using units
« on: March 14, 2017, 04:30:37 pm »
Hello Soldaters.
Does anyone use the units actively in scriptcore? I understand that unit provides me interface and the possibility to call its methods, change variables, kind of OOP approach(btw is it possible to create own objects in soldats pascalscript?). But how is it intended to work? I get that its kind of a module which extends the main function of a script but what if I want to use oncommand or ontick events there? They would collide, wont they? I guess there is no such thing as override and only one unit takes over. Or are the units supposed to be called just for simple user-written tasks when needed?
I have just rediscovered this game and wanted to have some fun but I got lost a bit and I would like to code a funny mode the proper way.
Any help appreciated.

Offline GymPolice

  • Major(1)
  • Posts: 42
  • What's that face?
Re: Using units
« Reply #1 on: March 15, 2017, 01:49:58 pm »
You are correct about them colliding. Back when I was still writing scripts for Soldat servers I've used units to clean up the main script from functions that I'd use often, or add math functions that are not included in standard Pascal. Comes in quite handy!
noun ~
Word used by programmers when they
do not want to explain what they did.

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Using units
« Reply #2 on: March 15, 2017, 03:26:20 pm »
Units are pascal way of expressing namespaces, nothing more, nothing less. They're supposed to sandbox their function/variable names in theory, however in pascalscript it doesn't happen because unit syntax support is experimental. So they're mearly for grouping stuff.
As for your questions about objects: No, you can't define your own classes in PS if that's what you wanted to ask. I can define classes as API types, but it's not possible for script to define it's own. You can create objects of classes defined in API though, assuming you can access constructor. (i.e. you can create TNewPlayer instances).
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.