Code for Objects in CS?

I see that several people have created object-oriented add ins for CS, but the code for all of them is gone. Does anyone have copies of any of these, code that allows for objects or classes, or a workaround that doesn’t involve 50 lines per object?

Umm… sorry, as I’m actually not an expert in coding, but what do you mean with objects/classes?

The only add-ins/add-ons/plug-ins/mods I know for CScript are fading your story’s background to another color, a save plugin, and “dedicated writing tools” for CScript.

There’s also a “prefab” or “blueprint” inventory system by @CitizenShawn
Is that :point_up_2: what you mean?

Sort of. More like this:

Oh, dayum. I know what you’re looking for, kind of.

It’s quite old stuff, as I see it. Even I barely heard of CoG or similar thing yet, at that time.

I’m not sure if anyone has the copy of it nor even raised similar topic as I recall,
but let me summon @CJW.


Do you still have the copy?

1 Like

Even if I did, I wouldn’t advise using it. The original author is long gone, and it may not even work properly with the current version of CS.

Recent CS developments have made this sort of thing a lot easier though, so I’d recommend sticking with vanilla CS if you can (or roll your own thing).

If anyone is interested I’d be happy to produce a tutorial/guide on using an OO paradigm in CS. I’ve been meaning to do so for a while, actually.

4 Likes

I absolutely would be interested, yes please! I do not look forward to trying to mimic random characters and encounters with 387463829 variables (random-character-837-name, random-character-837-strength, … ). There are ways around this, but OO would be sooooo much easier. In particular, some way to mimic an entity/component system would be awesome…

But are you preserving that data? Why not just reuse the variables?

Reuse the variables yes, when possible. It’s not always possible though, and a pain to create 5 unique random characters with 25 traits each using this method. One at a time is fine with reusing the variables and a generation subroutine, but… sometimes you need more than 1 at a time. Sometimes you need 20! Or more!

That was supposed to be an amusing example, though, not an absolutely accurate one.

1 Like

I mean, there are always going to be certain limitations. Creating xxx variables is always difficult (I’m still holding out for a *create_array command!). The only way you can streamline that sort of thing is a generation script.

Loops and array like syntax/clever naming will allow you to reference/handle multiple “objects” simultaneously.

EDIT: OO should allow you model ‘real-world’ “objects” and behaviour, in a more logical and efficient manner, but it’s not (inherently) meant to be a way to support handling a larger quantity of data. I.e. is this really the right tool for the job?

1 Like

If you can explain how to use clever naming, I’m all for it. I don’t the think objects are the only way, just the most obvious. If I can use clever naming and still only use 25 lines, instead of 125…

Can you give me an example of exactly what you want to achieve?

How about something like this?

*temp prefixcount 1
*temp suffixcount 1
*temp swordcount 1
*temp sword @{swordcount Sword|Broadsword|Greatsword|Katana}
*temp prefix @{prefixcount Holy|Unholy|Icy|Flaming}
*temp suffix @{suffixcount of Speed|of Strength|of Stamina|of Leeching}

Should be able to do a lot with this basic model, I think?
Hope this helps.

Edit: “Multireplace” is introduced here:

I’m building an rpg like game, never ending… well, unless you die.

There are random encounters and battle, with random people, some of whom can be recruited. I can create a generation script, but… you can fight more than one at a time. I’d need to create create multiples, which can be done without an object / array / etc, but… that’s 125 lines for 5 characters with 25 traits / stats / items each. I can reuse a single set of variables, if it’s always one on one, but… that’s not the goal/desire. Also, if I recruit one of these random characters, it’s 25 lines just to copy to one of the empty party slots.

A couple lines with an object would be sooooo much easier.

Is that a clear enough example? I can elaborate yet more, but I don’t know that it would really help…

CThanks Carlos, but that’s just a method for assigning random values to a variable. Do that 25 times for a character, and then do THAT 5 times for 5 random characters, and you can see what I’m trying to avoid. Consider a much simpler variable scheme…

Char1_name
Char1_element
Char2_name
Char2_element
Char3_name
Etc.

I have to set every variable for every character, instead of using one object that automatically generates the random values for the object. Make sense?

1 Like

Ok, but why not just make loops and tell it to quit the loop when certain conditions have been met?

If I could get the loop into the variable name some how (but I don’t see how… I’d be surprised, since very few languages allow dynamic variable names… that’s what objects and arrays are for)…

Think of it like this…

Loop until… (or whatever the syntax is for loops… haven’t needed it yet)

*set char1_name Fred

And on…

But for next character, still have to explicitly say char2_name. The loop does nothing for me. I’d still have to explicitly set every variable.

CS has an “array” syntax:

*set n "1"
*set charname[n] value
*comment same as *set charname_1 value
3 Likes

Woot! That’s all I need then.

Is there proper documentation somewhere? I thought there was no array anything (hence the wishing for a *create_array command.

1 Like
2 Likes

You can also combine the array syntax with curly braces {} (just gonna copy/paste some code from a game I was working on before getting sidetracked):

*label cost_disp_calcs
*temp n_1 "tax_inc"
*temp n_2 "perm_inc"
*temp n_3 "maint_cost"
*temp n_4 "city_funds"
*temp loopn 0
*temp n "n"
*temp thou "_thou"
*temp hun "_hun"
*temp p "_p"

*label calc_loop
*set loopn (loopn + 1)
*set {n[loopn]&thou} (({n[loopn]} - ({n[loopn]} modulo 1000)) / 1000)
*if ({n[loopn]&thou} > 0)
	*set {n[loopn]&p} true
*if ({n[loopn]&thou} = 0)
	*set {n[loopn]&p} false
	*set {n[loopn]&thou} ""
*if ({n[loopn]} modulo 1000) = 0
	*set {n[loopn]&hun} 000
*if (({n[loopn]} modulo 1000) > 0) and (({n[loopn]} modulo 1000) < 10)
	*set {n[loopn]&hun} ("00"&({n[loopn]} modulo 1000))
*if (({n[loopn]} modulo 1000) > 9) and (({n[loopn]} modulo 1000) < 100)
	*set {n[loopn]&hun} ("0"&({n[loopn]} modulo 1000))
*if ({n[loopn]} modulo 1000) > 99
	*set {n[loopn]&hun} ({n[loopn]} modulo 1000)
*if (loopn = 4)
	*if not(started)
		*goto dialogue_start
	*else
		*return
*goto calc_loop

So the point of this loop was literally just to make the display of large numbers look pretty (13,500 instead of 13000) across several variables…

So, for example, {n[loopn]&thou} would set the variables “tax_inc_thou”, “perm_inc_thou”, “maint_cost_thou”, and “city_funds_thou”.

3 Likes