variable for coordinates?

Started by milkev, March 27, 2016, 05:55:04 PM

Previous topic - Next topic

milkev

is it possible to get a single value for a coord? like if i only want the X coordinate but not the y one so that i can edit it. I want to create a digitalis path that will create itself as the previous one gets a certain level of creeper. im currently thinking of have the crpl core test its current coords, then create a digitalis a certain distance away from it defined by differencex and differencey. Ex differencex = 2 once the creeper level is at the required level it will create a piece of digitalis(it will be dead) 2 "blocks" to the crpls right.

Edit: this is what i currently have, but it doesn't do anything. it seems right to me.....

$differencex:1
$differencey:1

CurrentCoords GetCreeper 0 gt if
   SetDigitalis(<-CurrentCoordX <-differencex add <-CurrentCoordY <-differencey add 0)

endif


TheTiconTech

Man you must use SetDigitalisGrowth instead of SetDigitalis. Everything else is fine, except you must change the last argument from 0 to 1.

J


milkev

So then it would be like this?

$differencex:1
$differencey:1

CurrentCoords GetCreeper 0 gt if
   SetDigitalis(CurrentX <-differencex add CurrentY <-differencey add 1)

endif



it still doesnt work for me.

GoodMorning

You may need to SetDigitalisGrowth first. Growth is the white bit, SetDigitalis will adjust health, but not create it. See the CRPL docs on the wiki. https://knucklecracker.com/wiki/doku.php?id=crpl:docs:setdigitalisgrowth
A narrative is a lightly-marked path to another reality.

Vanguard

Quote from: milkev on March 28, 2016, 03:29:05 PM
So then it would be like this?

$differencex:1
$differencey:1

CurrentCoords GetCreeper 0 gt if
   SetDigitalis(CurrentX <-differencex add CurrentY <-differencey add 1)

endif



it still doesnt work for me.

Apart from what Goodmorning posted - just some basic questions, which you should clarify: did you attach the script to a CRPL.core? Did the core come into contact with creeper?

Suggestion: Attach a trace to your core and check the outputs. Always use "showtracelog" in the "once" section of your script and use "trace" to output information for debugging.


A minimum effort solution should at least look like this, so you can give more information that we can work with:

once
# Remember to use once to lighten the load of your scripts, static variables do not need to be set each and every time.
# Remember to use inline documentation, not only for our, but for your sake as well
$differencex:1
$differencey:1
showtracelog
endonce

trace(CurrentCoords GetCreeper) # tracing the amount of creeper detected on terrain
CurrentCoords GetCreeper 0 gt if
        trace("The if condition was fulfilled #arbitrary mark to follow code#")
SetDigitalis(CurrentX <-differencex add CurrentY <-differencey add 1)
endif

# Import delay - not many scripts need to be run every frame.
10 delay



This should give you more info, like: Was the IF condition fulfilled successfully, etc. pp.

milkev

Quote from: Vanguard on March 31, 2016, 05:12:12 AM
Quote from: milkev on March 28, 2016, 03:29:05 PM
So then it would be like this?

$differencex:1
$differencey:1

CurrentCoords GetCreeper 0 gt if
   SetDigitalis(CurrentX <-differencex add CurrentY <-differencey add 1)

endif



it still doesnt work for me.

Apart from what Goodmorning posted - just some basic questions, which you should clarify: did you attach the script to a CRPL.core? Did the core come into contact with creeper?

Suggestion: Attach a trace to your core and check the outputs. Always use "showtracelog" in the "once" section of your script and use "trace" to output information for debugging.


A minimum effort solution should at least look like this, so you can give more information that we can work with:

once
# Remember to use once to lighten the load of your scripts, static variables do not need to be set each and every time.
# Remember to use inline documentation, not only for our, but for your sake as well
$differencex:1
$differencey:1
showtracelog
endonce

trace(CurrentCoords GetCreeper) # tracing the amount of creeper detected on terrain
CurrentCoords GetCreeper 0 gt if
        trace("The if condition was fulfilled #arbitrary mark to follow code#")
SetDigitalis(CurrentX <-differencex add CurrentY <-differencey add 1)
endif

# Import delay - not many scripts need to be run every frame.
10 delay



This should give you more info, like: Was the IF condition fulfilled successfully, etc. pp.

it tells me that the if condition was fulfilled, but does not place any digitalis. it also says your line of comments in the if statement, and a number that increases by random decimals.

eX:

12.94167
The if condition was fulfilled
#arbitrary mark to follow code#

GoodMorning

To explain the trace log:
The number is the amount of Creeper detected.
The text, including what looks like a comment, is a single text string.
It is traced when the if condition is fulfilled, just as it says.
It's a long bit of text, so the trace window wraps to the next line.

Note on comments:
Comment #Blah
Text: "Blah #Blah"
Inside a string, the # is just another character.

To attempt to fix your problem:

SetDigitalisGrowth(CurrentX <-differencex add CurrentY <-differencey add true)
SetDigitalis(CurrentX <-differencex add CurrentY <-differencey add 1)
A narrative is a lightly-marked path to another reality.

Vanguard

#8
Lunch break. Taking a bit of time to think about your problem. Here´s an example of how I´d do it.

State the problem: Create a self-creating digitalis path from top left to bottom right ( at least that´s what I gathered from your code the idea is. 0/0 in CW3 is the top left corner, if I remember correctly, thus adding 1 to X and Y should go to the bottom right... right? ).

Break the problem down in simple problems and pseudo code:

1) Get the conditions for digitalis growth.
2) IF matched -> Grow Ditialis at the new position.
3) SAVE the new position.
4) repeat and iterate

Write the code. make sure I have debugging output and comments, so I can take a step back and understand what i did there.



once
# Always have a once section and put everything here I really only use once.
# Fetching current position
currentX ->xcoord
currentY ->ycoord
#Activate trace
ShowTraceLog
# More once stuff needed? For example you could put variables here which you´d like to easily manipulate. A timer for example
30 ->delaytimer
endonce

# Is the digitalis growth warranted at new coords?
# The conditions I want are "a certain amount of creeper at my current location" or rather "at the last used position".
# if I´d always use the "current coords" of my CRPL core, the digitalis would always get created at the same location
<-xcoord <-ycoord GetCreeper 1 gt if
trace("Yes, please grow some digitalis. Sprout from X/Y: " <-xcoord <-ycoord concat concat)
# First we add to our current coordinates, because we grow the digitalis there and next time we check the creeper amount at these coordinates.
1 <-xcoord add ->xcoord
1 <-ycoord add ->ycoord
trace ("Target Digitalis Location X/Y: " <-xcoord <-ycoord concat concat)
# Digitalis growth code suggestion by GoodMorning
SetDigitalisGrowth(<-xcoord <-ycoord true)
SetDigitalis(<-xcoord <-ycoord 1)
# Digitalis gowth should be done now, not anything left to do in this IF
endif

<-delaytimer delay


As always, compile the script and check for errors. This might do the trick.

If you´d like to expand upon the script, here is an idea with code in spoilers: Subtract an amount of creeper at the location where you sprout the digitalis from. ( basically you use the creeper to grow digitalis )

Try to do it yourself and have a look at the code example for guidance if you need.

Spoiler

#insert into once
5 ->creeperamount

#modifty the IF statement to:
<-xcoord <-ycoord GetCreeper <-creeperamount gt if

#insert in code before you manipualte the coordinates
<-xcoord <-ycoord <-creeperamount neg AddCreeper
[close]

GoodMorning

#9
If you want it to be reusable, and adjust the Creeper cost of making Digi, use:

$CreepCost:5


Looking back at your original script, you will need to shift the Core after each Digi creation, whereas Vanguard has used a static Core, that could sit invisibly outside the map. Which is better depends on what you want to achieve with the map.

Also, beware the fact that your Digi wire, in that form, will be only on the diagonal, and so will not connect, as Digi doesn't grow on a diagonal. To illustrate:

Spoiler

Yours  Will Grow
O----  OO---
-O---  -OO--
--O--  --OO-
---O-  ---OO
----O  ----O
[close]

I think we have answered in somewhat more depth than you required, but the original problem seems to have been the Digi Growth not being set.

Also, from the original question, the most common way to get only one coord is to write "CurrentCoords ->Y ->X" and modify from there, because you usually want to do something to each, and it's a fairly minor bit of code.

Vanguard, (0,0) is the top left.
A narrative is a lightly-marked path to another reality.

Vanguard

Quote from: GoodMorning on April 01, 2016, 08:53:49 AM
Also, beware the fact that your Digi wire, in that form, will be only on the diagonal, and so will not connect, as Digi doesn't grow on a diagonal. To illustrate:

Goes to show how rarely I work with Digitalis. Thanks for the info.

Of course, Milkev, that should easily fiable. You can simply call the set digitalis twice and increase the X and Y coordinates in between seperately.

X+1
Placedigitalis
Y+1
Placedigitalis


Let us know what you think. :)

J

Quote from: GoodMorning on April 01, 2016, 08:53:49 AM
Also, beware the fact that your Digi wire, in that form, will be only on the diagonal, and so will not connect, as Digi doesn't grow on a diagonal. To illustrate:

Spoiler

Yours  Will Grow
O----  OO---
-O---  -OO--
--O--  --OO-
---O-  ---OO
----O  ----O
[close]
Fixed for readability. Do not put code blocks in spoilers, code in spoilers can barely be read in most browsers. Such small 'code' can easily be put outside the spoiler, and code blocks automatically make code scrollable if it's too large.

Builder17

I believe forum automatically changed it to code , doesn't it do so?  ???

milkev

#13
Quote from: Builder17 on April 01, 2016, 11:04:58 AM
I believe forum automatically changed it to code , doesn't it do so?  ???

its never done that for me....


anyway, i wasnt thinking of moving the core or having it stationary outside the map, my original idea was to have a path of 1x1 crpl cores and they would self destruct after placing there piece of digi.
so, the core works. thanks to you guys... but it wont do anything except blow up if i set it to make the digitalis to the left of it. (ie differencex = -1) :( do i have to change what type of variable it is?

Edit: PS does work if the difference is posotive.

GoodMorning

The line of self-destructing cores makes little sense to me, however...

The issue with the negative seems odd, but could be produced by the Core trying to look at somewhere outside map bounds, perhaps.

As ever, try using a Trace to examine what's actually happening.


As to nested tags:
OK, I didn't know that... my browser renders it at normal size. I was using the code tags to make sure the O and - characters lined up.
Is it the spoilers that shrink it, or the code, or both?

I don't work with Digi much either, but had been looking at a map with a broken wire like that earlier.
A narrative is a lightly-marked path to another reality.