Can you save a script in a variable and have the variable make the unit? (DONE)

Started by TLFP, January 12, 2016, 07:51:48 PM

Previous topic - Next topic

TLFP

Quote from: Builder17 on January 14, 2016, 01:25:44 PM
Should you go looking better into CRPL section of wiki?
knucklecracker.com/wiki/doku.php?id=crpl:start
That's how I figure out my scripts. I just want a script that creates random units at the cost of some creeper and places them randomly around a area.
Currently ghosting, don't mind me.
Christian, my list of various content creation groups can be found here

GameGibu

Quote from: Grayzzur on January 14, 2016, 09:13:35 AM
Quote from: GameGibu on January 14, 2016, 09:11:14 AM
To randomize:

RandInt(0 5) "scriptSuffix" concat ".crpl" concat ->RandScriptName
#then
<-unit <-RandScriptName AddScriptToUnit


Hope that helps!
-GameGibu
That works too, but don't forget to concat ".crpl" to the end of the script name as well.

Note that RandInt(A B) generates numbers from A to (B-1). In the above example, 0-4. This works well with my use of a list above, as there are 5 list elements, numbered 0-4.

It was assumed ScriptSuffix contained .crpl already...
Bringing you Custom maps since 2971!
☆CRPL Master☆

GameGibu

Quote from: TheLongFellowPLAYERThe code I'm trying to randomize is intended to be a PAC with sleeper units map. It's supposed to create ONE core if there is creeper under it, destroy creeper under it, and attach ONE script to it per 10 seconds. Instead, it attaches 0-2 scripts to a core and does it 1 every .5 seconds and causes LAG.

Scripts run 30 times per second. Make a variable that increments every invocation, and

if(<-myTime <-DelayInSeconds mul(30) mod eq0)
    #execute timed stuff
endif

Using delay is kinda sloppy and messes up timing. This method always works for me.

-GameGibu
Bringing you Custom maps since 2971!
☆CRPL Master☆

TLFP

Quote from: GameGibu on January 15, 2016, 07:13:16 AM
Quote from: TheLongFellowPLAYERThe code I'm trying to randomize is intended to be a PAC with sleeper units map. It's supposed to create ONE core if there is creeper under it, destroy creeper under it, and attach ONE script to it per 10 seconds. Instead, it attaches 0-2 scripts to a core and does it 1 every .5 seconds and causes LAG.

Scripts run 30 times per second. Make a variable that increments every invocation, and

if(<-myTime <-DelayInSeconds mul(30) mod eq0)
    #execute timed stuff
endif

Using delay is kinda sloppy and messes up timing. This method always works for me.

-GameGibu
Now it's not working at all. :-\ CODE:$NeededAmount:50
#Self CONST_MAXAMMO <-NeededAmount SetUnitAttribute
if(<-creeperAmount <-NeededAmount  gte)
if(<-myTime <-DelayInSeconds mul(30) mod eq0)
    #execute timed stuff

0 5 RandInt ->Creep
150 delay
"CRPLCore" 33 26 12 RandCoordsInRange CreateUnit ->unit
if(<-Creep 1 eq)
<-unit "CCannon.crpl" AddScriptToUnit
endif
if(<-Creep 2 eq )
<-unit "CSniper.crpl" AddScriptToUnit
endif
if(<-Creep 3 eq)
<-unit "CSprayer.crpl" AddScriptToUnit
endif
if(<-Creep)
<-unit "CMortar.crpl" AddScriptToUnit
endif
endif
CurrentCoords 0 Setcreeper
<-creeperAmount <-creeperAmount sub ->creeperAmount
delay 30
endif

if(<-time neq0)
<-time <-time sub ->time
endif
I don't know if I did a newbie mistake.
Currently ghosting, don't mind me.
Christian, my list of various content creation groups can be found here

GameGibu

At the beginning of your code MUST be

once
0 ->myTime
endonce
<-myTime add(1) ->myTime

You have to increment it. And lose the delay, that will break the whole thing!

If you want 10 seconds, replace <-DelayInSeconds with the number 10.

-GameGibu

Maybe I could just optimize your code for you if you want.
Bringing you Custom maps since 2971!
☆CRPL Master☆

TLFP

#20
Quote from: GameGibu on January 15, 2016, 09:14:18 AM
At the beginning of your code MUST be

once
0 ->myTime
endonce
<-myTime add(1) ->myTime

You have to increment it. And lose the delay, that will break the whole thing!

If you want 10 seconds, replace <-DelayInSeconds with the number 10.

-GameGibu

Maybe I could just optimize your code for you if you want.
If you could find the bug in my script and point it out...once
0 ->myTime
endonce
<-myTime add(1) ->myTime
$NeededAmount:50
#Self CONST_MAXAMMO <-NeededAmount SetUnitAttribute
if(<-creeperAmount <-NeededAmount  gte)
if(<-myTime 10 mul(30) mod eq0)
    #execute timed stuff

0 5 RandInt ->Creep
150 delay
"CRPLCore" 33 26 12 RandCoordsInRange CreateUnit ->unit
if(<-Creep 1 eq)
<-unit "CCannon.crpl" AddScriptToUnit
endif
if(<-Creep 2 eq )
<-unit "CSniper.crpl" AddScriptToUnit
endif
if(<-Creep 3 eq)
<-unit "CSprayer.crpl" AddScriptToUnit
endif
if(<-Creep)
<-unit "CMortar.crpl" AddScriptToUnit
endif
endif
CurrentCoords 0 Setcreeper
<-creeperAmount <-creeperAmount sub ->creeperAmount
endif

if(<-time neq0)
<-time <-time sub ->time
endif
...because I ran this at 4x speed for a while and nothing happened so I don't know if I'm supposed to rename stuff.
You could make another script that works, just make sure it spawns the units in this one and only this one because the custom units us textures that the PAC map overwrites so I changed the position of said scripts for only some of them. I will credit you if you do that.  8)
Currently ghosting, don't mind me.
Christian, my list of various content creation groups can be found here

GameGibu

Working on optimizing code right now. It'll require you to rename some scripts, unless those scripts are referenced by name in any other scripts, in which case you need to tell me that as soon as possible so I can rewrite to correct for this.

-GameGibu
Bringing you Custom maps since 2971!
☆CRPL Master☆

TLFP

Quote from: GameGibu on January 15, 2016, 12:06:35 PM
Working on optimizing code right now. It'll require you to rename some scripts, unless those scripts are referenced by name in any other scripts, in which case you need to tell me that as soon as possible so I can rewrite to correct for this.

-GameGibu
Thanks! I'll credit you  :D
Currently ghosting, don't mind me.
Christian, my list of various content creation groups can be found here

GameGibu

So you are able to change your script names without screwing up the other scripts? I need confirmation on this to give you the best version of the code.

-GameGibu
Bringing you Custom maps since 2971!
☆CRPL Master☆

TLFP

Quote from: GameGibu on January 15, 2016, 04:36:26 PM
So you are able to change your script names without screwing up the other scripts? I need confirmation on this to give you the best version of the code.

-GameGibu
The names are used in MULTIPLE scripts other than this one.
Currently ghosting, don't mind me.
Christian, my list of various content creation groups can be found here

GameGibu

Aye, acknowledged.

Please list the (5?) script names that need to be applied
Then I can post the fixed code.

-GameGibu
Bringing you Custom maps since 2971!
☆CRPL Master☆

TLFP

Quote from: GameGibu on January 15, 2016, 05:32:45 PM
Aye, acknowledged.

Please list the (5?) script names that need to be applied
Then I can post the fixed code.

-GameGibu
There's more than 5.

  • CMortar
  • CShotMortar
  • CCannon
  • CShot
  • CBeam
  • CSniper
  • CSprayer
These are case sensitive, and also add the .crpl on the back. Plus the CShot.crpl is used by more than one creep. Cheers :D
Currently ghosting, don't mind me.
Christian, my list of various content creation groups can be found here

GameGibu

CShot is one of the towers that needs to be randomly spawned?

Almost done except for that...

-GameGibu
Bringing you Custom maps since 2971!
☆CRPL Master☆

GameGibu

Assuming those scripts CMortarShot.crpl and CShot.crpl will be used by the towers this script is creating, here is your long-awaited optimized code:
Bringing you Custom maps since 2971!
☆CRPL Master☆

TLFP

#29
Quote from: GameGibu on January 16, 2016, 12:04:43 AM
Assuming those scripts CMortarShot.crpl and CShot.crpl will be used by the towers this script is creating, here is your long-awaited optimized code:
Thanks! I'll put your credit in my map and in my map list!  8)
EDIT: For some strange reason, I can't comment out the (now) useless code.
EDIT2: Ok, now it's working. Thanks again!  :D
Currently ghosting, don't mind me.
Christian, my list of various content creation groups can be found here