Author Topic: Some questions, again  (Read 2700 times)

A few questions:
-Is there a reverse getsubstr(); ? Like, for getting the last 3 letters of any string, no matter its length?
-Is there a function for getting the datablock count of an add-on?
-Why does exec(); sometimes crash a server? I'm not facing this issue, I just want to know so I can make my own force run script for any add-on.

To get the last characters of a string, you can still use getsubstr() like this (pretty much ripped from gamemode_stranded's rpchat.cs):
Code: [Select]
getsubstr(%string,strlen(%string)-3,3);Note that if the string is less than 3 characters, it'll return an error.

Also, here is a good reference for string functions + other functions you can use.

edit: removed strlen(%string) at last argument since it's unnecessary; the amount of characters you want returned goes there and must be the same or greater than the number the 2nd arg is getting subtracted by to be the true end even though they should be the same numbers all the time
« Last Edit: May 04, 2015, 09:43:31 PM by QuadStorm »

The only real way to get the datablock count of an add-on is to write a parser to look for datablock declarations

exec crashes BL because of bad add-ons
There's no way to answer more specifically without a console log/add-on code

Blockland detects the number of datablocks an add-on adds in a pretty simple way: It just loads it and then sees if the size of the datablock group has changed. Obviously this only works once per add-on until you clear out the datablock group and start over, and Blockland doesn't save the number, only echoes it to the console, but depending on the context you might be able to make some use of it.

-Why does exec(); sometimes crash a server? I'm not facing this issue, I just want to know so I can make my own force run script for any add-on.
Only two reasons why it ever would.

- The code you're executing just crashes in whatever context you're using it.
or
- You executed code which contains local variables (outside of functions) in the global scope (aka: the black box console).